-
Notifications
You must be signed in to change notification settings - Fork 13.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
mpsc::send returns error once, then success #32114
Comments
I may be a bit confused, but it looks like everything is working as intended here? In the first example the receiver is immediately dropped (binding via The second example also looks correct as when the first message is sent the receiver is still active (could possibly acquire the message), but afterwards it's guaranteed to never be received so the next two sends are errors. |
The code here demonstrates the problem https://users.rust-lang.org/t/mpsc-sender-send-only-returns-senderror-once-then-succeeds/4894 |
Aha! So to inline the problem: use std::sync::mpsc::{channel, SendError};
fn main() {
let (tx, _) = channel();
let _ = tx.send(123);
assert_eq!(tx.send(123), Err(SendError(123)));
} Yes, this is indeed unexpected behavior! It's probably something to do with the upgrade logic in channels. |
I think the issue here is that |
Restore `DISCONNECTED` state in `oneshot::Packet::send` Closes #32114 I'm not sure if this is the best approach, but the current action of swapping `DISCONNECTED` with `DATA` seems wrong. Additionally, it is strange that the `send` method (and others in the `oneshot` module) takes `&mut self` despite performing atomic operations, as this requires extra discipline to avoid data races and lets us use methods like `AtomicUsize::get_mut` instead of methods that require a memory ordering.
If you close the rx side of a channel pair before sending to it, then the first send will fail with a
SendError
as expected, but a second send will returnOk(())
.Fails with:
However, if something is successfully sent before the receiver is dropped (even if it never receives the value), then it works as expected:
The text was updated successfully, but these errors were encountered: