Skip to content

Documenting cancel safety of SinkExt::send()Β #2754

Open
@jgallagher

Description

@jgallagher

I think SinkExt::send() is not cancel safe:

  1. When send() is called, the item is moved into a Send (and from there into its inner Feed)
  2. When the Send is polled, it waits until its feed is ready, which in turn waits until the underlying sink is ready.
  3. If the underlying sink is not ready and the Send is dropped before it becomes ready, the item will be dropped with the Send and never sent to the underlying sink.

I tried to confirm this with a custom Sink that is not ready for some period of time and a select! that tries to send() items to it with a timeout: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=2608a62c8695fbcfbb22d1856bfe930a. The first two items (which time out before the sink is ready) are never delivered.

A couple of questions:

  • Is this analysis correct?
  • If so, could I open a PR adding an explicit "Cancel safety" section to StreamExt::send()'s docs to note that it is not cancel safe?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions