You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I guess setting p.cancelFunc in makeQueryOptionsWithContext should be protected by p.stopLock, but it's less obvious to me how to protect the places where p.cancelFunc is called.
One option might be to turn p.stopLock into a RWMutex and do this in the places where it is called:
although this is kind of ugly... Another option might be to return a local copy of cancel from makeQueryOptionsWithContext and call that in the places where p.cancelFunc is currently called (except for inside Stop of course).
I'm happy to submit a patch for either of these two options (or any other way you can think of to slice this).
Thank you, this indeed looks like a real race. Note that only cancelFunc in Stop has a race since all the other calls have a guaranteed non-concurrent read-after-write since they're strictly serial. Regardless, there is a race between Stop and the init.
Overview of the Issue
When using the
github.com/hashicorp/consul/watch
package as a library in client code, there appears to be a data race detected by the race detector. Full race detector output is in this gist: https://gist.github.com/KJTsanaktsidis/acef6be673f311488c4ee06d80d74b81It appears to be a race between setting
p.cancelFunc
here:and reading it here:
I guess setting
p.cancelFunc
inmakeQueryOptionsWithContext
should be protected byp.stopLock
, but it's less obvious to me how to protect the places wherep.cancelFunc
is called.One option might be to turn
p.stopLock
into a RWMutex and do this in the places where it is called:although this is kind of ugly... Another option might be to return a local copy of
cancel
frommakeQueryOptionsWithContext
and call that in the places wherep.cancelFunc
is currently called (except for insideStop
of course).I'm happy to submit a patch for either of these two options (or any other way you can think of to slice this).
Reproduction Steps
I had this function to setup a Consul watch, and was running in the race detector. It's not a full program but I think it illustrates the issue - see shardelection.go in the gist: https://gist.github.com/KJTsanaktsidis/acef6be673f311488c4ee06d80d74b81
This was using the
v1.2.0
tag of Consul.Consul info for both Client and Server
N/A, it's a client library issue
Operating system and Environment details
The text was updated successfully, but these errors were encountered: