release-23.1: server: avoid a race in the server controller #108457
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.
Backport 1/1 commits from #108401 on behalf of @knz.
/cc @cockroachdb/release
Co-authored with @lidorcarmel
Prior to this patch, the Go race detector was complaining about racy concurrent accesses to
serverStateUsingChannels.server
, via(*serverStateUsingChannels) getServer()
and(*channelOrchestrator) startControlledServer()
.These racy accesses happened to be safe because the writes and reads to that field were correctly ordered around updates to an atomic bool (the
started
field). However, the race detector is not sufficiently sophisticated to detect this ordering and satisfy itself that the state transition can only happen once.In order to silence the race detector (with no change in correctness), this patch replaces the atomic bool by a mutex, whose access semantics are properly understood by the race detector.
This change incidentally makes the code slightly easier to read and understand.
Supersedes #108371.
Fixes #107930.
Epic: CRDB-28893
Release justification: avoids test flakes