Skip to content

Question about Sink's poll_flush and channels: mpsc senders don't fully flush the buffer before returning Poll::Ready #2504

Open
@FSMaxB

Description

@FSMaxB

Maybe this is just a misunderstanding of what poll_flush actually means, but from the documentation I would expect poll_flush of the Sink trait to only return Poll::Ready once all buffered messages have been received by the Receiver of the channel, meaning the buffer is empty.

/// Returns `Poll::Ready(Ok(()))` when no buffered items remain. If this
/// value is returned then it is guaranteed that all previous values sent
/// via `start_send` have been flushed.

Currently the Sink implementation for Sender and UnboundedSender don't do that though, making poll_flush almost equivalent to poll_ready. See:

fn poll_flush(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
match (*self).poll_ready(cx) {
Poll::Ready(Err(ref e)) if e.is_disconnected() => {
// If the receiver disconnected, we consider the sink to be flushed.
Poll::Ready(Ok(()))
}
x => x,
}
}

In the Unbounded case, it doesn't flush anything at all:

fn poll_flush(self: Pin<&mut Self>, _: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
Poll::Ready(Ok(()))
}

Is this intentional? And if so, how does this relate to the documentation of the Sink trait? Maybe the documentation can be updated to clarify this?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions