flume icon indicating copy to clipboard operation
flume copied to clipboard

SendError cannot be sent between threads?

Open stevefan1999-personal opened this issue 3 years ago • 1 comments

error[E0277]: `SinkItem` cannot be shared between threads safely
   --> tarpc\src\transport\channel.rs:130:45
    |
130 |             .map_err(|e| ChannelError::Send(Box::new(e)))
    |                                             ^^^^^^^^^^^ `SinkItem` cannot be shared between threads safely
    |
    = note: required because it appears within the type `flume::SendError<SinkItem>`
    = note: required for the cast from `flume::SendError<SinkItem>` to the object type `dyn StdError + std::marker::Send + Sync`
help: consider restricting type parameter `SinkItem`
    |
123 | impl<Item, SinkItem: std::marker::Sync> Sink<SinkItem> for Channel<Item, SinkItem> {
    |                    +++++++++++++++++++

This is what ChannelError looks like:

/// Errors that occur in the sending or receiving of messages over a channel.
#[derive(thiserror::Error, Clone, PartialEq, Eq, Debug)]
pub enum ChannelError {
    /// An error occurred sending over the channel.
    #[error("an error occurred sending over the channel")]
    Send(#[from] Box<dyn Error + Send + Sync + 'static>),
    #[error("the channel is closed and cannot accept new items for sending")]
    Closed
}

So it seems like I have to limit the bound of SinkItem to Send + Sync? but far as I know futures::channel::mpsc::Sender does not require that

stevefan1999-personal avatar Dec 23 '22 04:12 stevefan1999-personal

That same requirement definitely exists on futures::channel::mpsc::Sender: the channel has the capacity to send data between threads, so that data must be thread-safe. It might be that the requirement is simply on an impl in futures, but it'll still be there.

zesterer avatar Dec 28 '22 12:12 zesterer