Skip to content

AsyncConnectionPool leaks connection on CancelledError on 3.8 #149

Description

@lazitski-aliaksei

From python 3.8 CancelledError a is subclass of BaseException (https://docs.python.org/3.8/library/asyncio-exceptions.html#asyncio.CancelledError)

If coroutine is cancelled after connection was acquired and during request, connection is not removed from the pool:
https://github.com/encode/httpcore/blob/master/httpcore/_async/connection_pool.py#L179

try:
    response = await connection.request(
        method, url, headers=headers, stream=stream, timeout=timeout
    )
except NewConnectionRequired:
    connection = None
except Exception:
    logger.trace("remove from pool connection=%r", connection)
    await self._remove_from_pool(connection)
    raise

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