-
-
Notifications
You must be signed in to change notification settings - Fork 15k
std::sync::mpsc::Sender::send can block the current thread #157728
Copy link
Copy link
Open
Labels
A-concurrencyArea: ConcurrencyArea: ConcurrencyA-docsArea: Documentation for any part of the project, including the compiler, standard library, and toolsArea: Documentation for any part of the project, including the compiler, standard library, and toolsC-bugCategory: This is a bug.Category: This is a bug.I-libs-api-nominatedNominated for discussion during a libs-api team meeting.Nominated for discussion during a libs-api team meeting.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.Relevant to the library API team, which will review and decide on the PR/issue.
Metadata
Metadata
Assignees
Labels
A-concurrencyArea: ConcurrencyArea: ConcurrencyA-docsArea: Documentation for any part of the project, including the compiler, standard library, and toolsArea: Documentation for any part of the project, including the compiler, standard library, and toolsC-bugCategory: This is a bug.Category: This is a bug.I-libs-api-nominatedNominated for discussion during a libs-api team meeting.Nominated for discussion during a libs-api team meeting.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.Relevant to the library API team, which will review and decide on the PR/issue.
Type
Fields
Give feedbackNo fields configured for issues without a type.
Location (URL)
https://doc.rust-lang.org/stable/std/sync/mpsc/struct.Sender.html#method.send
Summary
On the documentation for
send(), it states "This method will never block the current thread". However, internally it usesSyncWakerwhich uses a mutex to notify receivers. I believe this should be changed to something akin to "This method will never block the current thread for an unbounded length of time".I noticed this because I'm running WebAssembly in a browser's main thread, which disallows any sort of blocking. Thus, sending data through
Senders extremely rarely spuriously traps. I can work around this, but IMO the documentation should be clearer because this feels like a potential footgun.An alternative conclusion is that
Sender::sendshouldn't block at all and that the current behavior is a bug, but this would require a more involved solution.