7996: sync: fix notify_waiters priority in Notify#87
7996: sync: fix notify_waiters priority in Notify#87martin-augment wants to merge 1 commit intomasterfrom
notify_waiters priority in Notify#87Conversation
Previously, if a `notify_waiters()` was followed by a `notify_one()`, an unpolled `Notified` future created before the `notify_waiters()` call would consume the `NOTIFIED` permit created by the `notify_one()` call. This commit fixes this by verifying the `notify_waiters_calls` count before optimistically attempting to acquire the `NOTIFIED` permit. If the count indicates a `notify_waiters()` call has already happened, the future transitions directly to `State::Done` and leaves the permit intact for other waiters. Fixes: tokio-rs#7965
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
WalkthroughA guard condition was added to ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Code Review
This pull request updates the Notify synchronization primitive to improve state management during concurrent calls. It introduces a check within the Notified future's polling logic to detect changes in the notify_waiters call count, ensuring the future transitions to the Done state appropriately. A new test case was also added to verify that notify_one functions correctly alongside notify_waiters. I have no feedback to provide as no issues were identified.
🤖 Augment PR SummarySummary: Updates 🤖 Was this summary useful? React with 👍 or 👎 |
Code ReviewThis PR fixes a real bug (tokio-rs#7965) in CorrectnessThe fix is correct. In the 1. Missing comment on the new check The existing equivalent check inside the lock (line 1153) has a clear comment explaining its purpose. The new pre-lock check at line 1121 has no comment. Since this is a subtle correctness property (preventing permit theft by an Suggested addition: // If notify_waiters has been called after the future was created,
// transition to Done without consuming the NOTIFIED permit.
if get_num_notify_waiters_calls(curr) != *notify_waiters_calls {2. Inconsistent import in the test The test file already has 3. Slightly misleading test name
4. Informational: the pre-check is an optimization, not a correctness requirement If SummaryThe fix is logically sound and the test correctly captures the regression scenario. Items 1-3 are minor polish (comment, import style, test name) rather than blocking concerns. |
value:good-to-have; category:bug; feedback: The Claude AI reviewer is correct! The very same logic is executed few lines below (line 1153). It would be good to document why the same is needed again. |
value:good-to-have; category:bug; feedback: The Claude AI reviewer is correct! There is no need to use the fully qualified name since the Notify struct is already imported. |
value:good-to-have; category:bug; feedback: The Claude AI reviewer is correct! The proposed test name suggests that there is a priority order but there is no such. The name of the test could be improved to explain what it test instead. |
7996: To review by AI