[http2] Fast requests' results are not being returned to the caller until the slow ones on the same connection finish #1766
Unanswered
alekseyl1992
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
-
Real setting:
we need to send a lot of long-polling requests with different parameters to the same server
thankfully this server supports http/2, so we don't need to initiate a lot of tcp-connection and can use http2-streams
The problem:
Slow requests "pause" handling of the fast ones.
To reproduce the issue in a controlled environment, I have created a test server (in golang). This server sleeps upon receiving each request for 1 or 10 seconds depending in the
?fast=1
parameter in the url query (it doesn't block other requests, the sleep is non-blocking operation). This makes it possible to see the interference between to kinds of requests: slow and fast ones, simulating the real long-polling situation.The server code
And I've written two test clients: one in python (using httpx) and one in golang.
Python client code
Now let's run the server and the Python client and see the client's output:
As you can see, I've recieved 9 "fast" responses with 1 seconds interval each, than 1 slow one after 10 seconds interval - that's all expected.
But after that "fast" requests are being responded each 10 seconds. Why?
From the real setting I know that "fast" requests' responses are being consumed by the caller code only when the slow one finishes.
It seems like there is some kind of connection locking issue inside of
httpcore
library which blocks the whole connection waiting for the data on one (in that case slow) stream.To make sure that there is not issue with the server code, I've written another test client - in golang.
Golang client code
And the output is perfectly fine:
Each fast request being responded once per second.
The slow ones being responded once per 10 seconds.
Apparently
httpx/httpcore
blocks fast responses waiting for the other (slow) requests to finish. And golang client doesn't have this problem: all the streams are being handled independently.I've tried removing
read_lock
in thehttpcore
's http2 implementation, but it didn't help :(Versions
Python 3.8.1
httpx[http2]==0.18.2
go1.13.4
Beta Was this translation helpful? Give feedback.
All reactions