Skip to content

New httpcore stubs (v8.0+) cause httpx to eventually run out of connections #977

@warhammerkid

Description

@warhammerkid

Description

If you do not close real_response.stream then httpcore does not detect that the connection is free for reuse, and eventually you run out of available connections.

Detail

# Reading the response stream consumes the iterator, so we need to restore it afterwards
real_response_content = b"".join([part async for part in real_response.stream])
real_response.stream = ByteStream(real_response_content)

The above code reads from the stream, but never calls aclose which is responsible for releasing the connection back to the pool for reuse.

The httpx library would normally take care of that for us, because it naturally closes responses after they're completely read. However, because we're replacing the async stream with a ByteStream here, that original aclose is never called.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions