Controller: panic on concurrent access to NamespaceQueues.workers map
A panic was observed while testing the controller:
fatal error: concurrent map read and map write
goroutine 79 [running]:
runtime.throw(0x15f692e, 0x21)
/usr/local/go/src/runtime/panic.go:608 +0x72 fp=0xc000d73b88 sp=0xc000d73b58 pc=0x42b252
runtime.mapaccess2_faststr(0x140ede0, 0xc0005aade0, 0xc000d3b400, 0x5, 0x42cfbb, 0x167b370)
/usr/local/go/src/runtime/map_faststr.go:110 +0x458 fp=0xc000d73bf8 sp=0xc000d73b88 pc=0x411f68
code.uplex.de/uplex-varnish/k8s-ingress/pkg/controller.(*NamespaceQueues).StopNS(0xc00051f180, 0xc000d3b400, 0x5)
The map accessed in StopNS()
is the workers
field of NamespaceQueues
.
Evidently a race, because this code has been around for a quite a while, and this is the first time I've ever seen that. The controller Pod was restarted, and the tests continued without any error (so this might have happened before after all, I was just watching the log when it happened this time.)
Fix by ensuring safe access to the map.