agiledragon / gomonkey

gomonkey is a library to make monkey patching in unit tests easy
MIT License
1.93k stars 179 forks source link

测试过程中GC可能导致panic #23

Closed RYAN--LEE closed 3 years ago

RYAN--LEE commented 3 years ago

apply的时候生成的中间函数是临时变量,过程中遇到gc之后,再调用测试函数会出现panic

agiledragon commented 3 years ago

你确定?产品代码运行过程中GC会导致panic吗?

RYAN--LEE commented 3 years ago

执行过程中遇到了,平时使用过程中偶现,在patch和执行之间gc或者等两分钟强制gc会必现。看了逻辑应该是中间创建的函数只做了地址拷贝,没有被变量引用,gc时可能被释放。尝试把getDoubleFunc 出来的内容保存一份后,就不会出现了。

RYAN--LEE commented 3 years ago

d := getDoubleFunc(funcType, outputs) return this.ApplyCore(t, d)

这个d 在ApplyCore里只使用了地址,没有做引用到本身,gc的时候可能会被释放掉

agiledragon commented 3 years ago

嗯,可以提个PR

agiledragon commented 3 years ago

v2.0.2