Skip to content

Problems with handling update window in tokio_yamux crate #33

@mcrakhman

Description

@mcrakhman

Hi all!

I tried to use your library for my simple project related to sending files.

I have the code looking like stream.write_all(...).await. The problem is that when the self.send_window == 0 the writer waits until it is waken up by handle_window_update. The window update is actually being received by the session and successfully sent to frame_receiver channel. But because nobody is reading this (i.e. nobody is actually polling the stream), the window can't be updated and the write is stuck forever.

I looked in other solution related to Yamux in Rust (https://github.com/libp2p/rust-yamux), and it seems they actually solve this problem by updating windows on the "session" side not on the stream side (see below), so you don't need to poll the stream, the "session" side manages the window frames (so I assume my code would work as it is, I will try to do it to confirm).

https://github.com/libp2p/rust-yamux/blob/81913c4d85544a8a0453b7fa17021d0ef7aba7e2/yamux/src/connection.rs#L726C9-L739C10

if let Some(s) = self.streams.get_mut(&stream_id) {
    let mut shared = s.lock();
    shared.increase_send_window_by(frame.header().credit());
    if is_finish {
        shared.update_state(self.id, stream_id, State::RecvClosed);
  
        if let Some(w) = shared.reader.take() {
            w.wake()
        }
    }
    if let Some(w) = shared.writer.take() {
        w.wake()
    }
}

Please correct me if I'm missing something, thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions