Skip to content

Increase Aiohttp connector limit #1490

@seangastinov

Description

@seangastinov

When making multiple concurrent requests, the client often encounters intermittent aiohttp disconnection errors (e.g., aiohttp.client_exceptions.ServerDisconnectedError). This appears to stem from restrictive connection limits and insufficient keep-alive configurations in the default TCPConnector.

By increasing the connector limits and extending the keep-alive timeout, the client should maintain more stable and persistent connections under high concurrency.

Proposed Change
`
if self._aiohttp_session is None or self._aiohttp_session.closed:
AIOHTTP_CONNECTOR_LIMIT = 100
AIOHTTP_KEEPALIVE_TIMEOUT = 60

connector = aiohttp.TCPConnector(
    limit=AIOHTTP_CONNECTOR_LIMIT,
    keepalive_timeout=AIOHTTP_KEEPALIVE_TIMEOUT,
    enable_cleanup_closed=True,
    force_close=False  # Reuse connections
)

self._aiohttp_session = aiohttp.ClientSession(
    connector=connector,
    trust_env=True,
    read_bufsize=READ_BUFFER_SIZE,
)

`

Metadata

Metadata

Assignees

Labels

priority: p3Desirable enhancement or fix. May not be included in next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.type: feature request‘Nice-to-have’ improvement, new feature or different behavior or design.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions