Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tolerate send_open() at Closed state? #803

Open
vilicvane opened this issue Oct 14, 2024 · 2 comments
Open

Tolerate send_open() at Closed state? #803

vilicvane opened this issue Oct 14, 2024 · 2 comments

Comments

@vilicvane
Copy link

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(());
        }

pub fn send_open(&mut self, eos: bool) -> Result<(), UserError> {
let local = Streaming;
self.inner = match self.inner {
Idle => {
if eos {
HalfClosedLocal(AwaitingHeaders)
} else {
Open {
local,
remote: AwaitingHeaders,
}
}
}
Open {
local: AwaitingHeaders,
remote,
} => {
if eos {
HalfClosedLocal(remote)
} else {
Open { local, remote }
}
}
HalfClosedRemote(AwaitingHeaders) | ReservedLocal => {
if eos {
Closed(Cause::EndStream)
} else {
HalfClosedRemote(local)
}
}
_ => {
// All other transitions result in a protocol error
return Err(UserError::UnexpectedFrameType);
}
};
Ok(())
}

Any suggestions on a proper workaround?

@seanmonstar
Copy link
Member

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

@vilicvane
Copy link
Author

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:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants