Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix max_keepalive_connections #1000

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

blazewicz
Copy link

@blazewicz blazewicz commented Mar 26, 2025

Summary

This commit fixes a bug in both sync and async connection pools where idle connections were dropped from the pool even when max_keepalive_connections limit has not been reached. This happened because the check compared this setting's value to the total number of connections, not only of the idle ones.

Checklist

  • I understand that this PR may be closed in case there was no previous discussion. (This doesn't apply to typos!)
  • I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change.
  • I've updated the documentation accordingly.

async with pool.stream("GET", "http://example.com/") as response:
async with pool.stream("GET", "http://example.com/") as response_1, pool.stream(
"GET", "http://example.com/"
) as response_2:
info = [repr(c) for c in pool.connections]
assert info == [
"<AsyncHTTPConnection ['https://example.com:443', HTTP/1.1, IDLE, Request Count: 2]>",
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This connection is dropped without the fix.

with pool.stream("GET", "http://example.com/") as response:
with pool.stream("GET", "http://example.com/") as response_1, pool.stream(
"GET", "http://example.com/"
) as response_2:
info = [repr(c) for c in pool.connections]
assert info == [
"<HTTPConnection ['https://example.com:443', HTTP/1.1, IDLE, Request Count: 2]>",
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This connection is dropped without the fix.

@blazewicz blazewicz force-pushed the blazewicz/fix-max-keepalive-connections branch from d147c94 to 0aa2ee1 Compare March 28, 2025 19:57
This commit fixes a bug in both sync and async connection pools
where idle connections were dropped from the pool even when
max_keepalive_connections limit has not been reached. This
happened because the check compared this number to the total
number of connections, not only the idle ones.
@blazewicz blazewicz force-pushed the blazewicz/fix-max-keepalive-connections branch from 0aa2ee1 to 6414fd8 Compare March 29, 2025 18:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant