问题: 当我使用errgroup并发读数据库时发生了panic
报错信息:
fatal error: concurrent map writes
goroutine 2183 [running]: runtime.throw(0x2168afc, 0x15) /usr/local/go/src/runtime/panic.go:1117 +0x72 fp=0xc00117cc88 sp=0xc00117cc58 pc=0x4386b2 runtime.mapassign_faststr(0x1dc1780, 0xc000de45d0, 0xc000df68e0, 0x1a, 0xe) /usr/local/go/src/runtime/map_faststr.go:211 +0x3f1 fp=0xc00117ccf0 sp=0xc00117cc88 pc=0x414991 gorm.io/gorm/schema.(Schema).parseRelation(0xc000ee0000, 0xc000efddc0, 0xc000ea4dc0) /go/pkg/mod/gorm.io/gorm@v1.21.14/schema/relationship.go:95 +0x985 fp=0xc00117cdd8 sp=0xc00117ccf0 pc=0x8ba425 gorm.io/gorm/schema.Parse(0x1c7c600, 0xc000e9eee8, 0xc00044e210, 0x24c4718, 0xc00044e180, 0x0, 0x0, 0x0) /go/pkg/mod/gorm.io/gorm@v1.21.14/schema/schema.go:239 +0x1fc5 fp=0xc00117d5a8 sp=0xc00117cdd8 pc=0x8c31c5 gorm.io/gorm.(Statement).Parse(0xc000e91a40, 0x1c7c600, 0xc000e9eee8, 0xc000e9efa8, 0xc0007316d0) /go/pkg/mod/gorm.io/gorm@v1.21.14/statement.go:447 +0x79 fp=0xc00117d640 sp=0xc00117d5a8 pc=0x8ef9f9 gorm.io/gorm.(processor).Execute(0xc0000e8780, 0xc000ea2840, 0x21468e8) /go/pkg/mod/gorm.io/gorm@v1.21.14/callbacks.go:105 +0x6d1 fp=0xc00117d738 sp=0xc00117d640 pc=0x8d6991 gorm.io/gorm.(DB).Find(0xc000ea2840, 0x1c7c600, 0xc000e9eee8, 0x0, 0x0, 0x0, 0xc000ea2840) /go/pkg/mod/gorm.io/gorm@v1.21.14/finisher_api.go:166 +0xba fp=0xc00117d798 sp=0xc00117d738 pc=0x8dc91a pkg.poizon.com/ee/learning-go/internal/dao/db.(Dao).ExerciseMemberGetExercise2UserMap(0xc000486430, 0xc0002b6c80, 0xc000e740d0, 0x2, 0x2, 0xc000e9d1c0, 0x1, 0x1, 0x10, 0x0, ...) /tmp/goc-build-873a91e301e2/internal/dao/db/exercise_member.go:128 +0x2a5 fp=0xc00117ded0 sp=0xc00117d798 pc=0x11c2ca5 pkg.poizon.com/ee/learning-go/internal/service/learning_center_service.(LearningCenterClassInfoHandler).NcSrvClassListGetPlansProcess.func3(0x24b0ee0, 0xc000150030, 0x442936, 0x2210a60) /tmp/goc-build-873a91e301e2/internal/service/learning_center_service/class.go:954 +0xf4 fp=0xc00117df70 sp=0xc00117ded0 pc=0x175c814 pkg.poizon.com/ee/learning-go/internal/pkg/errgroup.(Group).do(0xc000d7b1f0, 0xc000f829b0) /tmp/goc-build-873a91e301e2/internal/pkg/errgroup/errgroup.go:66 +0xa2 fp=0xc00117dfd0 sp=0xc00117df70 pc=0x115be42 runtime.goexit() /usr/local/go/src/runtime/asm_amd64.s:1371 +0x1 fp=0xc00117dfd8 sp=0xc00117dfd0 pc=0x472861 created by pkg.poizon.com/ee/learning-go/internal/pkg/errgroup.(Group).Go /tmp/goc-build-873a91e301e2/internal/pkg/errgroup/errgroup.go:100 +0x18a
请问这个是我操作的问题,还是gorm遇到了不安全的操作?
Comment From: github-actions[bot]
The issue has been automatically marked as stale as it missing playground pull request link, which is important to help others understand your issue effectively and make sure the issue hasn't been fixed on latest master, checkout https://github.com/go-gorm/playground for details. it will be closed in 30 days if no further activity occurs. if you are asking question, please use the Question template, most likely your question already answered https://github.com/go-gorm/gorm/issues or described in the document https://gorm.io ✨ Search Before Asking ✨
Comment From: Softwarekang
I encountered the same problem today. Are there any other guidelines for this issue? @jinzhu