hyperium / h2

HTTP 2.0 client & server implementation for Rust.
MIT License
1.37k stars 273 forks source link

Tolerate send_open() at Closed state? #803

Open vilicvane opened 2 days ago

vilicvane commented 2 days ago

I am having some issue with tunneling TCP using h2, it aborts the connection after the server (usually speedtest servers) resets the connection and h2 trying to send_open().

Not sure if this should be tolerated by h2 or to be handled by my code. I tried to do an early return with a Closed state and it seems to fix my problem.

    pub fn send_open(&mut self, eos: bool) -> Result<(), UserError> {
        let local = Streaming;

        if matches!(self.inner, Inner::Closed(_)) {
            return Ok(());
        }

https://github.com/hyperium/h2/blob/77be6648e5c6da22f51e5049347496335a032288/src/proto/streams/state.rs#L91-L129

Any suggestions on a proper workaround?

seanmonstar commented 2 days ago

That's not a publicly exposed method outside the crate. What are you actually calling, and what behavior is problematic?

vilicvane commented 2 days ago

I didn't call it directly, it just resulted in aborting the h2 connection in my case.

  1. The server receives a request and gets the remote address to connect.
  2. It connects the remote and do a bidirectional copy.
  3. In this case the speedtest servers close the connection immediately, results in an already closed stream (I suppose) even before h2 internally calls send_open().

Related lines in my codebase: