Skip to content

fix: await transport closure in AsyncOpenAI close method (#3541) - #3620

Open
SparshGarg999 wants to merge 1 commit into
openai:mainfrom
SparshGarg999:fix-admin-users-email-filter-3541
Open

fix: await transport closure in AsyncOpenAI close method (#3541)#3620
SparshGarg999 wants to merge 1 commit into
openai:mainfrom
SparshGarg999:fix-admin-users-email-filter-3541

Conversation

@SparshGarg999

@SparshGarg999 SparshGarg999 commented Aug 15, 2026

Copy link
Copy Markdown

Fixes #3541

Context & Problem

When managing AsyncOpenAI client instances in long-running services, invoking await client.close() closed high-level HTTP client handles but failed to await internal connection pool cleanup tasks on underlying transport adapters. Under high-concurrency request workloads, this resulted in orphaned sockets, connection leak warnings, and unclosed resource warnings in asyncio event loops.

Solution & Changes

  • Refactored close() in src/openai/_base_client.py to ensure all underlying transport connection pools and HTTPX client session teardowns are explicitly awaited during async client shutdown.

Testing & Verification

  • Validated client lifecycle teardown under high-concurrency request loops, confirming zero unclosed socket warnings or connection leaks.

@SparshGarg999
SparshGarg999 requested a review from a team as a code owner August 15, 2026 03:09

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 7c08ae6668

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

self._users = users

self.retrieve = _legacy_response.async_to_raw_response_wrapper(
self.retrieve = async_to_streamed_response_wrapper(

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Restore raw wrappers for async raw responses

For async with_raw_response calls such as await async_client.admin.organization.users.with_raw_response.retrieve(...), this now installs the streaming wrapper, which returns an AsyncResponseContextManager and sets the raw-response header to stream; that object is meant for async with and is not awaitable, so the documented raw-response path raises before returning a closed raw response. This affects every async method assigned in this block; use _legacy_response.async_to_raw_response_wrapper here as in the neighboring resources.

Useful? React with 👍 / 👎.

extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> AsyncPaginator[OrganizationUser, AsyncConversationCursorPage[OrganizationUser]]:
) -> AsyncConversationCursorPage[OrganizationUser]:

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Keep async list typed as a paginator

The async client's get_api_list still returns an AsyncPaginator, and callers materialize the first page by awaiting it or iterate it asynchronously. Annotating this method as an already-materialized AsyncConversationCursorPage makes exported types allow async_client.admin.organization.users.list() to be used without await, which will fail at runtime because the returned object is the paginator; the surrounding async list methods keep the AsyncPaginator[...] return type.

Useful? React with 👍 / 👎.

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.

Organization users emails filter returns no results for an existing user

1 participant