diff options
author | Carl Lerche <me@carllerche.com> | 2020-09-21 14:29:22 -0700 |
---|---|---|
committer | Carl Lerche <me@carllerche.com> | 2020-09-21 14:35:09 -0700 |
commit | 93f8cb8df2bb0dceb7921556165a8ed8efed9151 (patch) | |
tree | 964a5ce89407b7ad602ab148927087fbfbbaa86e /tokio/tests | |
parent | 1ac10fa80aa847c68e376ebf9ef4e2be891e41d3 (diff) |
sync: fix missing notification during mpsc close (#2854)
When the mpsc channel receiver closes the channel, receiving should
return `None` once all in-progress sends have completed. When a sender
reserves capacity, this prevents the receiver from fully shutting down.
Previously, when the sender, after reserving capacity, dropped without
sending a message, the receiver was not notified. This results in
blocking the shutdown process until all sender handles drop.
This patch adds a receiver notification when the channel is both closed
and all outstanding sends have completed.
Diffstat (limited to 'tokio/tests')
-rw-r--r-- | tokio/tests/sync_mpsc.rs | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/tokio/tests/sync_mpsc.rs b/tokio/tests/sync_mpsc.rs index f571a71c..919bddbf 100644 --- a/tokio/tests/sync_mpsc.rs +++ b/tokio/tests/sync_mpsc.rs @@ -534,3 +534,25 @@ async fn blocking_send_async() { let (mut tx, _rx) = mpsc::channel::<()>(1); let _ = tx.blocking_send(()); } + +#[test] +fn ready_close_cancel_bounded() { + use futures::future::poll_fn; + + let (mut tx, mut rx) = mpsc::channel::<()>(100); + let _tx2 = tx.clone(); + + { + let mut ready = task::spawn(async { poll_fn(|cx| tx.poll_ready(cx)).await }); + assert_ready_ok!(ready.poll()); + } + + rx.close(); + + let mut recv = task::spawn(async { rx.recv().await }); + assert_pending!(recv.poll()); + + drop(tx); + + assert!(recv.is_woken()); +} |