Skip to content

Conversation

@alanbriolat
Copy link
Contributor

Fixes #4118.

Motivation

try_reserve() and try_reserve_owned() of tokio::sync::mpsc::Sender are inconsistent with try_send() in the error they return, signalling Full instead of Closed for a closed channel. If other code relies on this error as documented, it might forever retry sending to a closed channel.

Solution

I copied the handling of the TryAcquireError from try_send() to try_reserve() and try_reserve_owned(); as far as I can tell, this is probably what it should have been in the first place when try_reserve() was introduced by 672be92, and then try_reserve_owned() just copied try_reserve() behaviour.

@Darksonn Darksonn added A-tokio Area: The main tokio crate M-sync Module: tokio/sync labels Sep 18, 2021
@alanbriolat alanbriolat force-pushed the mpsc-sender-try-reserve-closed branch from 0ef4713 to 86d32b2 Compare September 18, 2021 12:31
Copy link
Contributor

@Darksonn Darksonn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@Darksonn Darksonn merged commit e9f6fae into tokio-rs:master Sep 19, 2021
@Darksonn Darksonn mentioned this pull request Sep 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-tokio Area: The main tokio crate M-sync Module: tokio/sync

Projects

None yet

Development

Successfully merging this pull request may close these issues.

mpsc: try_reserve() gives TrySendError::Full(()) for closed channel

2 participants