Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

panic: reflect: call of reflect.Value.FieldByName on ptr Value #18

Closed
sutra opened this issue Sep 25, 2020 · 6 comments
Closed

panic: reflect: call of reflect.Value.FieldByName on ptr Value #18

sutra opened this issue Sep 25, 2020 · 6 comments

Comments

@sutra
Copy link

sutra commented Sep 25, 2020

类似的错误很容易发生,能看出来是什么原因吗:

panic: reflect: call of reflect.Value.FieldByName on ptr Value

goroutine 67 [running]:
github.com/jinzhu/gorm.(*Scope).callCallbacks.func1(0xc000113d80)
	/root/go/pkg/mod/github.com/jinzhu/gorm@v1.9.16/scope.go:865 +0xb0
panic(0x13b4ea0, 0xc00063cbc0)
	/home/jenkins/tools/org.jenkinsci.plugins.golang.GolangInstallation/go-lang-1.13/src/runtime/panic.go:679 +0x1b2
reflect.flag.mustBe(...)
	/home/jenkins/tools/org.jenkinsci.plugins.golang.GolangInstallation/go-lang-1.13/src/reflect/value.go:208
reflect.Value.FieldByName(0x13aad00, 0xc00063cba0, 0x196, 0x121f13c, 0x2, 0xc00063cba0, 0x196, 0xc00060d640)
	/home/jenkins/tools/org.jenkinsci.plugins.golang.GolangInstallation/go-lang-1.13/src/reflect/value.go:890 +0x1ed
github.com/8treenet/gcache/internal.(*easyScope).EasyPrimarys(0xc0004ccb00, 0x1616ed8, 0x8, 0xc0000486c0, 0x3c, 0xc00060d630)
	/root/go/pkg/mod/github.com/8treenet/gcache@v1.1.10/internal/easy_scope.go:497 +0xbcf
github.com/8treenet/gcache/internal.(*queryHandle).BySearch(0xc0000196f8, 0xc0004ccb00, 0xc00063c080, 0x197, 0x203000, 0x203000, 0x203000)
	/root/go/pkg/mod/github.com/8treenet/gcache@v1.1.10/internal/handle_query.go:109 +0xf7
github.com/8treenet/gcache/internal.(*callQuery).bySearch(0xc0003cc340, 0xc0004ccb00, 0x0, 0x0, 0x0, 0x0)
	/root/go/pkg/mod/github.com/8treenet/gcache@v1.1.10/internal/call_query.go:118 +0xd6
github.com/8treenet/gcache/internal.(*callQuery).invoke.func1(0x413031, 0xd0, 0x14a1860, 0xfba41cc9035f6801)
	/root/go/pkg/mod/github.com/8treenet/gcache@v1.1.10/internal/call_query.go:53 +0x75
github.com/8treenet/gcache/internal.(*Group).doCall(0xc0003cc348, 0xc000491f20, 0xc000040690, 0x4c, 0xc0000198a0)
	/root/go/pkg/mod/github.com/8treenet/gcache@v1.1.10/internal/singleflight.go:91 +0x2e
github.com/8treenet/gcache/internal.(*Group).Do(0xc0003cc348, 0xc000040690, 0x4c, 0xc0000198a0, 0xe, 0xc00060d5c8, 0x2, 0xc000040690, 0x4c)
	/root/go/pkg/mod/github.com/8treenet/gcache@v1.1.10/internal/singleflight.go:61 +0x1ba
github.com/8treenet/gcache/internal.(*callQuery).invoke(0xc0003cc340, 0xc000113d80)
	/root/go/pkg/mod/github.com/8treenet/gcache@v1.1.10/internal/call_query.go:46 +0x1a8
github.com/jinzhu/gorm.(*Scope).callCallbacks(0xc000113d80, 0xc0003cce20, 0x4, 0x4, 0x0)
	/root/go/pkg/mod/github.com/jinzhu/gorm@v1.9.16/scope.go:869 +0x92
github.com/jinzhu/gorm.(*DB).Find(0xc0003e8270, 0x12caea0, 0xc00063c080, 0xc000633950, 0x3, 0x3, 0xc000633950)
	/root/go/pkg/mod/github.com/jinzhu/gorm@v1.9.16/main.go:354 +0x98
gitlab.com/example/dal/reader.(*Reader).GetProducts(0xc00048f580, 0xc000633950, 0x3, 0x3, 0xc00063c060, 0x2, 0x2, 0x2, 0xc0004d4240)
	/home/jenkins/workspace/example/dal/reader/product.go:19 +0xb4
gitlab.com/sensestar/example/payment/controllers.(*PaymentController).GetProducts(0x27c54b0, 0x19ed8e0, 0xc0005006c0, 0xc0004d4240, 0x27c54b0, 0xc0005006c0, 0xc000027b58)
	/home/jenkins/workspace/example/payment/controllers/payment.go:72 +0x4ee
gitlab.com/sensestar/example/payment._PaymentService_GetProducts_Handler(0x15ede00, 0x27c54b0, 0x19ed8e0, 0xc0005006c0, 0xc000490f60, 0x0, 0x19ed8e0, 0xc0005006c0, 0xc0004deb10, 0x10)
	/home/jenkins/workspace/example/payment/payment.pb.go:5483 +0x217
google.golang.org/grpc.(*Server).processUnaryRPC(0xc000210d00, 0x1a04620, 0xc0000ebe00, 0xc0004cc300, 0xc000089800, 0x2788aa0, 0x0, 0x0, 0x0)
	/root/go/pkg/mod/google.golang.org/grpc@v1.29.1/server.go:1082 +0x4fd
google.golang.org/grpc.(*Server).handleStream(0xc000210d00, 0x1a04620, 0xc0000ebe00, 0xc0004cc300, 0x0)
	/root/go/pkg/mod/google.golang.org/grpc@v1.29.1/server.go:1405 +0xd27
google.golang.org/grpc.(*Server).serveStreams.func1.1(0xc0004de9b0, 0xc000210d00, 0x1a04620, 0xc0000ebe00, 0xc0004cc300)
	/root/go/pkg/mod/google.golang.org/grpc@v1.29.1/server.go:746 +0xbb
created by google.golang.org/grpc.(*Server).serveStreams.func1
	/root/go/pkg/mod/google.golang.org/grpc@v1.29.1/server.go:744 +0xa1
@sutra
Copy link
Author

sutra commented Sep 25, 2020

是因为 model 没有设置 primary key 吗?

@8treenet
Copy link
Owner

是的

@sutra
Copy link
Author

sutra commented Sep 25, 2020

能否在没有设置 primary key 时仅给出警告日志,而不要 panic?

@8treenet
Copy link
Owner

不能啊,如果没主键这个缓存就没办法搞了,流程就走不下去了。缓存的关系靠主键的key 来识别的。
不过能接受的是,不设置主键的。直接跳过缓存处理。

@sutra
Copy link
Author

sutra commented Sep 25, 2020

是的,正在排查那些没有设置 primary key 的 model,model 太多了,漏设置的不少,一不小心就撞上 panic,服务 crash 了。

@8treenet
Copy link
Owner

设置下主键吧。因该不至于crash。 肯定有recover的。
你需要的话 我就做过个没主键跳过缓存处理。但这样就漏过了。
你看

@sutra sutra closed this as completed Sep 25, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants