Skip to content

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

Closed

Description

@sethmlarson

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.

Activity

  1. lovelydinosaur commented on Aug 27, 2019

    @lovelydinosaur
    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.

  2. ndhansen commented on Mar 2, 2020

    @ndhansen

    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?

  3. lovelydinosaur commented on Mar 2, 2020

    @lovelydinosaur
    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.

  4. ndhansen commented on Mar 3, 2020

    @ndhansen

    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?

  5. yeraydiazdiaz commented on May 13, 2020

    @yeraydiazdiaz
    Contributor

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

  6. transferred this issue fromencode/httpxon May 13, 2020
  7. yeraydiazdiaz commented on May 13, 2020

    @yeraydiazdiaz
    Contributor

    Yep, this issue is still present.

  8. lovelydinosaur commented on May 13, 2020

    @lovelydinosaur
    Member

    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.

  9. lovelydinosaur commented on May 13, 2020

    @lovelydinosaur
    Member

    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

  10. lovelydinosaur commented on May 13, 2020

    @lovelydinosaur
    Member

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

  11. lovelydinosaur commented on May 13, 2020

    @lovelydinosaur
    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

  12. lovelydinosaur commented on May 13, 2020

    @lovelydinosaur
    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions