Skip to content

std::sync::mpsc::Sender::send can block the current thread #157728

@cyexclam

Description

@cyexclam

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 uses SyncWaker which 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::send shouldn't block at all and that the current behavior is a bug, but this would require a more involved solution.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-concurrencyArea: ConcurrencyA-docsArea: Documentation for any part of the project, including the compiler, standard library, and toolsC-bugCategory: This is a bug.I-libs-api-nominatedNominated 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.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions