Repository navigation
Initialize Notifier::waitStart_ before the first drain - #486
Open
rootkiller6788 wants to merge 1 commit into
Open
rootkiller6788 wants to merge 1 commit into
rootkiller6788 wants to merge 1 commit into
Conversation
shouldNotifyRelaxed() reads waitStart_ as soon as client_queue_wait_threshold_us is set, but the first write only happens at the end of a drain. Until then the read sees an indeterminate atomic value, which makes the forced-notification decision random. Seed it with the construction timestamp so the behavior before any drain is the same as right after one.
rootkiller6788
marked this pull request as ready for review
October 19, 2026 15:16
This branch has not been deployed
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.
Notifier tracks when the client queue was last drained in an atomic waitStart_. It is only ever written at the end of drainWhileNonEmpty(), and only read in shouldNotifyRelaxed(), and both branches are gated on client_queue_wait_threshold_us being nonzero. The constructor never initializes it, so with that option enabled the first relaxed-notify check before any drain reads an atomic that holds an indeterminate value. The "force a notification if the queue has not been drained in a while" decision then depends on garbage rather than on real time.
Fix: seed waitStart_ in the constructor with the current timestamp. Before the first drain it now looks the same as it would right after one, so the forced-notification logic is deterministic from the first request instead of relying on whatever was in that slot.
I could not reproduce this in a unit test without substantial plumbing (the Notifier is built inside MessageQueue and the threshold arrives via router options), but the defect is a plain missing member initializer and the change is one line in the init list.