http2: read timeout leaks stream #1058
Unanswered
jrafkind-ai
asked this question in
Potential Issue
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
If a server sets max concurrency streams to some number N (for example 100) for http2 connections, then if a client connection encounters enough read timeouts after sending requests to the server, the client can exhaust all of its available outbound streams. The actual error is
It seems that upon receiving a read timeout (or presumably a write timeout as well), that the logical stream is not reset (meaning, stream.closed is never true) and therefore future requests over the same connection simply increase the number of outbound streams.
Below are 3 files, one is a patch that resets the stream in case of read error, one is a test python that file purely uses httpcore, and another is a server that sets a limit of N streams per http2 connection. The server is written in golang. I tried to write a python server but wasn't behaving the same as the go one, I'm not sure why. I don't know if the proposed solution is good, but it does seem to make my example test case work properly.
Output of test case without patch:
You can see what happens is that the first three requests hit the server and all time out (as expected). But then the rest of the requests immediately hit the max outbound streams limit, and do not even send a request.
With the patch, every request is sent, and they all get the read timeout as expected.
To run the server/test case
test case
patch file:
httpcore-http2-timeout-stream-reset.patch
test file:
httpcore_h2_bug.py
go server:
main.go.txt
go.mod
go.mod.txt
Beta Was this translation helpful? Give feedback.
All reactions