Skip to content

Keep the pool from closing a connection assigned to a queued request - #1111

Open
moldhouse wants to merge 1 commit into
encode:masterfrom
moldhouse:pool-keeps-assigned-connections
Open

Keep the pool from closing a connection assigned to a queued request#1111
moldhouse wants to merge 1 commit into
encode:masterfrom
moldhouse:pool-keeps-assigned-connections

Conversation

@moldhouse

Copy link
Copy Markdown

Closes #1110.

_assign_requests_to_connections now treats a connection referenced by a pending PoolRequest as not idle, both when cleaning up connections and when picking an idle connection to close for making room. Without this a connection handed to a queued request could be closed by a concurrent pass before, or worse after, the request started on it.

The regression test drives the pool's assignment pass directly, since the race cannot be reproduced deterministically through the public API. scripts/unasync.py gains a httpcore._async -> httpcore._sync substitution so the test can import AsyncPoolRequest.

Assigning a connection to a PoolRequest leaves the connection IDLE
until the request starts on it, so a concurrent pass over the pool
could close it as surplus or to make room, sometimes underneath a
request that had already been sent. Closes encode#1110.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Connection pool can close a connection it has already assigned to a queued request

1 participant