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

Golang版OneList,多配置同时更新导致并发写map,程序panic #61

Open
tongyuantongyu opened this issue Dec 1, 2020 · 0 comments

Comments

@tongyuantongyu
Copy link

tongyuantongyu commented Dec 1, 2020

Traceback (已除去无关goroutine):

fatal error: concurrent map writes
fatal error: concurrent map writes

goroutine 8161 [running]:
runtime.throw(0x848925, 0x15)
	/usr/local/go/src/runtime/panic.go:774 +0x72 fp=0xc00043ae68 sp=0xc00043ae38 pc=0x42da82
runtime.mapassign_faststr(0x7c58c0, 0xc0001009f0, 0xc00011225c, 0x4, 0x0)
	/usr/local/go/src/runtime/map_faststr.go:291 +0x3fe fp=0xc00043aed0 sp=0xc00043ae68 pc=0x412dce
main.GetList(0xc000134000, 0xc000d3ae10, 0x2e)
	/tmp/OneList/OneList.go:396 +0x8e4 fp=0xc00043b1c0 sp=0xc00043aed0 pc=0x7678d4
main.GetList(0xc000134000, 0xc000413820, 0x1c)
	/tmp/OneList/OneList.go:394 +0x7b7 fp=0xc00043b4b0 sp=0xc00043b1c0 pc=0x7677a7
main.GetList(0xc000134000, 0xc0004134c0, 0x16)
	/tmp/OneList/OneList.go:394 +0x7b7 fp=0xc00043b7a0 sp=0xc00043b4b0 pc=0x7677a7
main.GetList(0xc000134000, 0xc00010e080, 0x11)
	/tmp/OneList/OneList.go:394 +0x7b7 fp=0xc00043ba90 sp=0xc00043b7a0 pc=0x7677a7
main.CacheRefreshMain(0xc000134000)
	/tmp/OneList/OneList.go:263 +0x8d fp=0xc00043bfd8 sp=0xc00043ba90 pc=0x765a5d
runtime.goexit()
	/usr/local/go/src/runtime/asm_amd64.s:1357 +0x1 fp=0xc00043bfe0 sp=0xc00043bfd8 pc=0x459f01
created by main.CacheRefresh
	/tmp/OneList/OneList.go:365 +0x344

goroutine 17 [semacquire]:
sync.runtime_Semacquire(0xb85150)
	/usr/local/go/src/runtime/sema.go:56 +0x42
sync.(*WaitGroup).Wait(0xb85148)
	/usr/local/go/src/sync/waitgroup.go:130 +0x64
main.CacheRefresh()
	/tmp/OneList/OneList.go:367 +0x198
main.Timer(0x85f498, 0x384, 0x4e5d01)
	/tmp/OneList/OneList.go:210 +0x96
created by main.main
	/tmp/OneList/OneList.go:858 +0xa5

goroutine 8162 [running]:
	goroutine running on other thread; stack unavailable
created by main.CacheRefresh
	/tmp/OneList/OneList.go:365 +0x344

goroutine 8162 [running]:
runtime.throw(0x848925, 0x15)
	/usr/local/go/src/runtime/panic.go:774 +0x72 fp=0xc000459158 sp=0xc000459128 pc=0x42da82
runtime.mapassign_faststr(0x7c58c0, 0xc0001009f0, 0xc000112268, 0x4, 0x0)
	/usr/local/go/src/runtime/map_faststr.go:291 +0x3fe fp=0xc0004591c0 sp=0xc000459158 pc=0x412dce
main.GetList(0xc000134080, 0xc0009b8780, 0x32)
	/tmp/OneList/OneList.go:396 +0x8e4 fp=0xc0004594b0 sp=0xc0004591c0 pc=0x7678d4
main.GetList(0xc000134080, 0xc000345600, 0x16)
	/tmp/OneList/OneList.go:394 +0x7b7 fp=0xc0004597a0 sp=0xc0004594b0 pc=0x7677a7
main.GetList(0xc000134080, 0xc000112270, 0x10)
	/tmp/OneList/OneList.go:394 +0x7b7 fp=0xc000459a90 sp=0xc0004597a0 pc=0x7677a7
main.CacheRefreshMain(0xc000134080)
	/tmp/OneList/OneList.go:263 +0x8d fp=0xc000459fd8 sp=0xc000459a90 pc=0x765a5d
runtime.goexit()
	/usr/local/go/src/runtime/asm_amd64.s:1357 +0x1 fp=0xc000459fe0 sp=0xc000459fd8 pc=0x459f01
created by main.CacheRefresh
	/tmp/OneList/OneList.go:365 +0x344

没有开源,我只能推测,问题应当出在OneList.go的396行,这一行应该是有一个map写操作,多个配置共享这一个缓存,如果同时进行更新就有可能出现此问题。
Golang的map不支持并发写,应当使用标准库的sync.Maphttps://golang.org/src/sync/map.go )或其他线程安全的map(如https://github.com/orcaman/concurrent-map )。

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

1 participant