Skip to content

Async client does not close underlying stream thus leaving connection active which leads to hitting pool limit #1315

Closed

Description

@daa

Checklist

  • The bug is reproducible against the latest release and/or master.
  • There are no similar issues or pull requests to fix it yet.

Describe the bug

AsyncClient doesn't close httpcore's stream after performing request, the bug shows itself in locking on connection pool's semaphore.

To reproduce

$ python3.8 -m asyncio
>>> import asyncio
>>> import httpx
>>> c = httpx.AsyncClient()
>>> await c.get('http://httpbin.org/')
<Response [200 OK]>
>>> c._transport._connections
{(b'http', b'httpbin.org', 80): {<AsyncHTTPConnection http_version=HTTP/1.1 state=2>}}
>>> await c.get('http://httpbin.org/')
<Response [200 OK]>
>>> c._transport._connections
{(b'http', b'httpbin.org', 80): {<AsyncHTTPConnection http_version=HTTP/1.1 state=2>, <AsyncHTTPConnection http_version=HTTP/1.1 state=2>}}

Expected behavior

There should be one connection in pool in IDLE state.

Actual behavior

There are 2 connection in ACTIVE state in pool after performing and finishing request.

Debugging material

Environment

  • OS: Linux
  • Python version: 3.8.5
  • HTTPX version: 0.15.0
  • Async environment: asyncio/trio
  • HTTP proxy: no
  • Custom certificates: no

Additional context

Bug is most obvious in long-running process making regular request to one endpoint.

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

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions