Skip to content

Initialize Notifier::waitStart_ before the first drain - #486

Open
rootkiller6788 wants to merge 1 commit into
meta:mainfrom
rootkiller6788:fix-notifier-waitstart-init
Open

rootkiller6788 wants to merge 1 commit into
meta:mainfrom
rootkiller6788:fix-notifier-waitstart-init

Conversation

@rootkiller6788

Copy link
Copy Markdown

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.

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.
@meta-cla meta-cla Bot added the CLA Signed label Oct 17, 2026
@rootkiller6788
rootkiller6788 marked this pull request as ready for review October 19, 2026 15:16

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant