Make bIsIdentified atomic - #3932
Merged
Merged
Conversation
bIsIdentified is written on the socket thread, by ResetInfo from CServer::InitChannel on every new connection and by SetChanInfo when channel info arrives, and read on the mix path in PrepAndSendPacket, which runs after the CServer::Mutex region in OnTimer has been released. No lock covers that pair, and ThreadSanitizer reports it as a data race. bIsEnabled just above it is already std::atomic<bool>. Nothing is added to the audio deadline path: the mix-thread read stays a plain load with no lock prefix and no fence.
pljones
approved these changes
Aug 30, 2026
softins
approved these changes
Aug 30, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
🤖 AI: Requested by @pljones by email, as the follow-up point on #3930.
bIsIdentifiedis written on the socket thread and read on the mix path with no lock common to the two, which ThreadSanitizer reports as a data race. It becomesstd::atomic<bool>, matchingbIsEnabledtwo lines above it.Short description of changes
One line: the
bIsIdentifieddeclaration becomesstd::atomic<bool>.<atomic>is already included, andbIsEnabledandiConTimeOutare already declared this way, so no call site changes.The writers run on the socket thread:
ResetInfofromCServer::InitChannelon every new connection, andSetChanInfowhen channel info arrives; both reached underCServer::MutexfromCServer::PutAudioData. The racing read is the early return inPrepAndSendPacket, reached fromMixEncodeTransmitData— whichOnTimerruns after releasing that mutex, and on the pool threads when multithreading is on. The other read is on the socket thread and is not part of this.ThreadSanitizer, server under 8-bot connect/send/disconnect churn with recording on, trimmed to the two stacks:
Those line numbers are from a build carrying #3930, where
ResetInfois out of line —mainalone cannot answer the question, because with recording on the use-after-free that #3930 closes ends the run at about 55 s, before this race samples. Two 600-second runs of the same rig, one binary each:PrepAndSendPacketAn earlier pair of runs on the same two binaries gave the same 1 and 0.
No misbehaviour has been observed from the race itself. The flag is read once per channel per mix cycle and the worst case is one packet sent or skipped on a stale value.
Nothing is added to the audio deadline path. In the generated code, gcc 13.3
-O2x86-64, the mix-path read goes fromcmpb $0x0,0x7b2(%rdi)tomovzbl 0x7b2(%rdi),%eaxplustest %al,%al— no lock prefix, no fence — andPrepAndSendPacketdisassembles to 101 instructions either way. The one locked instruction the change introduces is the store,xchg %al,(%r12)inSetChanInfo, on the socket thread.CHANGELOG: SKIP
Context: Fixes an issue?
Follow-up to #3930, which takes the channel
Mutexaround the writers. This closes the read side, which no lock covers. The two are independent and can merge in either order.Does this change need documentation? What needs to be documented and how?
No.
Status of this Pull Request
Ready for review.
What is missing until this pull request can be merged?
Review.
Checklist
🤖 This message was written by AI and reviewed by @mcfnord.