Add String method to ContextImpl to fix a race #2879
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What changed?
Add a
String
method (fmt.Stringer
) toContextImpl
.Also simplify
contextMatcher
implementation and movegetOrCreateShardRequestMatcher
to the bottom of the file just so the matchers are in one place.Why?
This is a weird one: in some tests, we use a gomock matcher to differentiate between
Context
s inCreateEngine
, to return the right value. Internally, gomock evaluates all its matchers, but for the failing ones (and there will always be failing ones if there's more than one), it constructs an error message usingSprintf("%v")
and then throws it away when it finds a match. The default"%v"
formatter reads private fields of the value being matched. Some of those private fields (e.g.state
) are protected by a mutex, but it doesn't know that and reads them anyway. This triggers the race detector. We can just provide aString
to bypass the default"%v"
behavior.How did you test it?
ran test with -race -count 1000