Skip to content

fix: Support pool_maxsize parameter for concurrent connections - #89

Open
kitaekatt wants to merge 1 commit into
msabramo:masterfrom
kitaekatt:fix-connection-pool-maxsize
Open

kitaekatt wants to merge 1 commit into
msabramo:masterfrom
kitaekatt:fix-connection-pool-maxsize

Conversation

@kitaekatt

Copy link
Copy Markdown

Summary

UnixHTTPConnectionPool was not passing maxsize to the parent HTTPConnectionPool, causing it to always use the default of 1. This resulted in noisy "Connection pool is full, discarding connection" warnings when making concurrent requests through a Unix socket.

Changes

  • UnixHTTPConnectionPool now accepts maxsize parameter and passes it to parent class
  • UnixAdapter now accepts pool_maxsize parameter (default 1 for backwards compatibility) and passes it to UnixHTTPConnectionPool

Usage

This allows users to configure larger connection pools for concurrent request scenarios:

adapter = UnixAdapter(pool_maxsize=10)
session.mount('http+unix://', adapter)

Backwards Compatibility

Default value of pool_maxsize=1 preserves existing behavior. Only users who explicitly set a larger pool size will see different behavior.

UnixHTTPConnectionPool was not passing maxsize to the parent
HTTPConnectionPool, causing it to always use the default of 1.
This resulted in "Connection pool is full, discarding connection"
warnings when making concurrent requests through a Unix socket.

Changes:
- UnixHTTPConnectionPool now accepts maxsize parameter and passes
  it to parent class
- UnixAdapter now accepts pool_maxsize parameter (default 1 for
  backwards compatibility) and passes it to UnixHTTPConnectionPool

This allows users to configure larger connection pools for
concurrent request scenarios:

    adapter = UnixAdapter(pool_maxsize=10)
    session.mount('http+unix://', adapter)
@mupuf

mupuf commented Dec 5, 2025

Copy link
Copy Markdown
Collaborator

Looks good to me, and thanks for the great commit message and PR!

@webknjaz webknjaz left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I see at least one more in _new_conn()

@kitaekatt

Copy link
Copy Markdown
Author

_new_conn() creates individual connections, not pools. maxsize is a pool-level setting passed to HTTPConnectionPool.init(). The parent _new_conn()
signature is just (self) with no pool config parameters.

@webknjaz

webknjaz commented Dec 7, 2025

Copy link
Copy Markdown
Collaborator

Ah, right. Could you add a test for the change?

@webknjaz

Copy link
Copy Markdown
Collaborator

_new_conn()

Looking into urllib3's source, I'd say we should stop redefining its private method and set the ConnectionCls class attribute instead.

This is out of the scope here but I'd still block merging on having at least some regression test coverage.

class UnixHTTPConnectionPool(urllib3.connectionpool.HTTPConnectionPool):

def __init__(self, socket_path, timeout=60):
def __init__(self, socket_path, timeout=60, maxsize=1, **kwargs):

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Ideally, the original version should have mirrored the upstream default... but this ship has sailed now and we don't want to regress on someone's code just for purity.

Let's start an issue about things that we want to fix for the next major version? There we could address your comment above about redefining private method.

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.

3 participants