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

Don't exceed MAX_CONCURRENT_STREAMS when sending HTTP/2 requests #85

Closed
sethmlarson opened this issue Aug 27, 2019 · 11 comments · Fixed by #89
Closed

Don't exceed MAX_CONCURRENT_STREAMS when sending HTTP/2 requests #85

sethmlarson opened this issue Aug 27, 2019 · 11 comments · Fixed by #89

Comments

@sethmlarson
Copy link

Bug described in encode/httpx#281 where HTTPX doesn't support waiting for other streams to close before creating a new stream on an HTTP/2 connection.

@tomchristie
Copy link
Member

Also noting http://http2.github.io/http2-spec/index.html#rfc.section.9.1 "Clients SHOULD NOT open more than one HTTP/2 connection to a given host and port pair" means that we shouldn't just open up a new conenction when we hit this limit.

@ndhansen
Copy link

ndhansen commented Mar 2, 2020

I'm familiar to asyncio but new to this project. Before I start working on this, my intuitive solution would be to wrap https://github.com/encode/httpx/blob/master/httpx/_dispatch/http2.py#L58-L63 in a semaphore, ideally one inheriting from the BaseSemaphore, with the same capacity as MAX_CONCURRENT_STREAMS.
That way it wouldn't acquire the lock before it has an available, and would wait until a stream becomes free.

Does that sound about right?

@tomchristie
Copy link
Member

@ndhansen Exactly correct yup, although I'd suggest on resolving this in https://github.com/encode/httpcore rather than here, since the intent is to move to that package for providing the core network dispatching.

@ndhansen
Copy link

ndhansen commented Mar 3, 2020

Thanks @tomchristie! Is there a branch in this project that already uses httpcore, or should I open a PR containing the equivalent code when the PR in httpcore is approved?

@yeraydiazdiaz
Copy link
Contributor

Moving this issue to httpcore, I feel this has already been addressed but we need to check.

@yeraydiazdiaz yeraydiazdiaz transferred this issue from encode/httpx May 13, 2020
@yeraydiazdiaz
Copy link
Contributor

Yep, this issue is still present.

@tomchristie
Copy link
Member

tomchristie commented May 13, 2020

Okay, so there's two related bit here...

Really we ought to tackle the second of those points, and then treat the first as an additional enhancement on top of that.

@tomchristie
Copy link
Member

tomchristie commented May 13, 2020

We should raise NewConnectionRequired() in either of those cases.

Are we already dealing with the MAX_CONCURRENT_STREAMS case, here?...

https://github.com/encode/httpcore/blob/master/httpcore/_async/http2.py#L94-L98

@tomchristie
Copy link
Member

Blergh, sorry - I'm mixing up max concurrent streams vs. max stream id.

@tomchristie
Copy link
Member

I suppose we want to wrap this block up in a semaphore...

https://github.com/encode/httpcore/blob/master/httpcore/_async/http2.py#L102-L105

@tomchristie
Copy link
Member

So, looks to me like https://github.com/encode/httpcore/pull/38/files has it about right, but really we should wrap the semaphore around the post-init part of the request method.

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

Successfully merging a pull request may close this issue.

4 participants