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
sync: Range reports concurrent map iterator and write #60216
Comments
Can you post code that reproduces this error? Can you try with 1.20? |
What happens if you run the program under the race detector? |
Regarding code actually It's a part of private codebase so it's difficult to share exact code and I didn't have luck to reproduce it with standalone sample code yet. Currently our project is on 1.20 only where this is being produced. Updated the same in bug info as well. |
I will give it a try and update the results here |
Sharing one stacktrace when tried to run it with race detector as suggested which includes sync/map.go:476 @bcmills WARNING: DATA RACE |
What's the full output of the race detector? There are always tell goroutines in a report. |
It was a long output but most relevant one was this WARNING: DATA RACE Previous write at 0x00c0003b4a50 by goroutine 212: Goroutine 208 (running) created at: Goroutine 212 (running) created at: ================== |
@hardik-cisco, does The two lines reported in the race are: The write is to the The
And all of the calls to That leads me to the hypothesis that To confirm or reject that hypothesis, please run |
@bcmills pls find the output of go vet on my program as below : `# cluster-agent/agent/metriclibrary/publish/upload cluster-agent/agent/testutilsagent/testutils/testutils.go:500:14: k8s.io/api/core/v1.Node struct literal uses unkeyed fields cluster-agent/agent/events/handlersagent/events/handlers/eventhandler.go:186:25: cluster-agent/agent/modules/clusterhealthmodule.HealthMonitoringEventData struct literal uses unkeyed fields cluster-agent/agent/modules/clusterhealthmoduleagent/modules/clusterhealthmodule/clusterhealth_test.go:153:22: cluster-agent/agent/modules/utils.PodInfoLite struct literal uses unkeyed fields cluster-agent/agent/modules/containermonitoringagent/modules/containermonitoring/containermonitoringmodule_test.go:245:21: cluster-agent/agent/swagger/containermonitoringapis.SimMachineMinimalDto struct literal uses unkeyed fields cluster-agent/agent/testutils/mocks/containermonitoringmoduleagent/testutils/mocks/containermonitoringmodule/IContainerMonitoringService.go:64:9: assignment copies lock value to r0: sync.Map contains sync.Mutex cluster-agent/agent/modules/utilsagent/modules/utils/utils.go:111:24: GetSyncMapLen passes lock by value: sync.Map contains sync.Mutex cluster-agent/agent/modules/metriccollectormoduleagent/modules/metriccollectormodule/clustermetriccollector.go:283:143: call of collector.ParseIndividualPodLevelMetric copies lock value: sync.Map contains sync.Mutex cluster-agent/agent/modules/metadatacollectormoduleagent/modules/metadatacollectormodule/metadatacollector_test.go:77:50: call of mockCM.On("GetRegisteredContainersInfo").Return copies lock value: sync.Map contains sync.Mutex cluster-agent/agent/modules/podmonitoringmoduleagent/modules/podmonitoringmodule/podmonitoring_test.go:1027:38: assignment copies lock value to podHostIdsFromLastRegistrationMap: sync.Map contains sync.Mutex cluster-agent/agent/modules/metriccollectormodule/metricsagent/modules/metriccollectormodule/metrics/nodemetric_test.go:22:19: cluster-agent/agent/modules/metadatacollectormodule/metadatatypes.NodeConditions struct literal uses unkeyed fields |
Also adding one more trace with golang version 1.20 where found race condition with race detector ================== WARNING: DATA RACE Previous write at 0x00c000a302a0 by goroutine 263: Goroutine 260 (running) created at: Goroutine 263 (running) created at: ================== |
@bcmills Below sample code can reproduce the error
If we remove the getMapLength call then sync map works fine, but if we want to use getMapLength in any of go routine parallel then concurrent read write error will be thrown. To resolve this case we have to explicitly take the locks and use the wait groups attached is the dirty solution which should be fixed. go vet output
-race output
|
Those Go values are not like Java references. If you pass a Go struct type by value, each field is copied. In the case of a |
closing as not a Go bug. |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes.
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
I have a sync map which is being used by multiple go routine running concurrently for read and write simultaneously . I increased the go routines to 1000 per minute (though it varies sometimes)
What did you expect to see?
As it is said that sync map is by default concurrent in nature I expect it to work fine even without taking any explicit lock.
What did you see instead?
Getting this error with sync map
fatal error: concurrent map iteration and map write
goroutine 259 [running]:
sync.(*Map).Range(0xc146047320?, 0xc122dabed8)
/usr/local/go/src/sync/map.go:349 +0x258
/modules/metadatacollectormodule.(*MetadataCollector).getRegisteredContainerMap(0xc000e42630)
The text was updated successfully, but these errors were encountered: