Skip to content

fix(mpsc): unregister receiver waker when pending recv is dropped - #496

Open
biaoma-ty wants to merge 1 commit into
apache:mainfrom
biaoma-ty:fix/mpsc-recv-drop-waker
Open

biaoma-ty wants to merge 1 commit into
apache:mainfrom
biaoma-ty:fix/mpsc-recv-drop-waker

Conversation

@biaoma-ty

@biaoma-ty biaoma-ty commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Track waiter registration in mpsc::BoundedReceiver::recv and unregister the receiver waker (clearing RX_WAITING_BIT and recv_slot_ticket) outside the control lock when a pending future is dropped.
  • Replace mpsc::UnboundedReceiver::recv's poll_fn wrapper with a handwritten Unpin Recv future that unregisters recv_waker outside the shared mutex on drop.
  • Update receiver waker callback tests to cover pending recv cancellation (cycle release while the receiver stays alive, reentrant waker_on_drop entering control.lock(), no spurious wakes, and in-flight slot cancellation) as well as leaked-future receiver drop and Unpin assertions.
  • Record the fix in CHANGELOG.md.

Design Notes

Tracking a three-state RecvState (Idle / Registered / Done) inside Recv keeps the non-suspending fast path and normal completion path completely lock-free without allowing an inconsistent (None, true) state: Drop takes the cold unregister path only when a future that previously returned Poll::Pending is dropped before completing. Existing mpsc_test::callbacks replacement and receiver-drop tests previously relied on a dropped recv() leaving its waker registered; they now keep the same Recv future alive across replacement polls and mem::forget a polled Recv to keep testing Drop for *Receiver waker cleanup.

@biaoma-ty
biaoma-ty force-pushed the fix/mpsc-recv-drop-waker branch from d0790fa to c3992b1 Compare December 3, 2026 07:00

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant