Skip to content

Add async client transport cleanup - #765

Open
jonathan343 wants to merge 1 commit into
developfrom
aiohttp-unclosed-issue
Open

Add async client transport cleanup#765
jonathan343 wants to merge 1 commit into
developfrom
aiohttp-unclosed-issue

Conversation

@jonathan343

Copy link
Copy Markdown
Contributor

Overview

This PR adds deterministic resource cleanup to generated clients and HTTP transports. It also preserves the configured transport across operation-level config copies so clients reuse one session and connection pool.

Current State

Each operation deep copies the client config, including its transport. This can create temporary HTTP clients, sessions, and connection pools that are discarded without cleanup. Applications may see repeated Unclosed client session and Unclosed connector warnings during shutdown.

New Pattern

Generated clients and HTTP transports now support close() and async context managers. Operation config copies retain the client-owned transport instead of copying it.

async with AsyncExampleClient(config) as client:
    response = await client.some_operation(input)

Clients can also be closed manually:

client = AsyncExampleClient(config)
try:
    response = await client.some_operation(input)
finally:
    await client.close()

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Generate close and async context manager methods for clients, and add matching
cleanup support to aiohttp and CRT transports. Preserve shared transports when
copying operation configs to avoid duplicating sessions and connection pools.
@jonathan343
jonathan343 requested a review from a team as a code owner August 9, 2026 04:29
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