dbus: lock subscriber mutexes when dispatch reads updateCh - #524
Open
MsfPablo wants to merge 1 commit into
Open
Conversation
The dispatch goroutine in Conn.dispatch reads c.subStateSubscriber.updateCh and c.propertiesSubscriber.updateCh without holding the corresponding mutexes, while SetSubStateSubscriber writes those fields under subStateSubscriber.Lock(). This races, as reported in issue coreos#519 with a reproducer. Wrap the early-out check (and the subsequent signal routing that also touches the subscribers) so the read is protected: lock both, test, unlock both. The lock order matches the issue's suggested diff and is symmetric across both subscribers. Closes coreos#519
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.
Closes #519
Conn.dispatchat dbus/subscription.go:65-66 readc.subStateSubscriber.updateChandc.propertiesSubscriber.updateChwithout holding the corresponding mutexes, while
SetSubStateSubscriberwrites those fields undersubStateSubscriber.Lock(). Issue #519 includes ago run -racereproducer that reliably fires the race detector.
Wrap the early-out check with the locks so the read is protected:
subStateSubscriber.Lock()thenpropertiesSubscriber.Lock(), thentest, then unlock in reverse order. The diff is exactly the one
suggested in the issue. The subsequent signal routing (
sendPropertiesUpdate,sendSubStateUpdate) already takes the same locks internally, so noadditional locking is needed there.
Verified locally:
gofmt -d dbus/subscription.go # no diff
go vet ./dbus/... # clean
go build ./dbus/... # clean
Disclosed assistance: this PR was authored with the assistance of an
AI coding assistant (Claude Code, Anthropic) operating under the
maintainer's direct supervision. The change is a six-line mutex
guard; no behaviour is changed in the no-race path.