fix: await transport closure in AsyncOpenAI close method (#3541) - #3620
fix: await transport closure in AsyncOpenAI close method (#3541)#3620SparshGarg999 wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
💡 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( |
There was a problem hiding this comment.
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]: |
There was a problem hiding this comment.
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 👍 / 👎.
Fixes #3541
Context & Problem
When managing
AsyncOpenAIclient instances in long-running services, invokingawait 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
close()insrc/openai/_base_client.pyto ensure all underlying transport connection pools and HTTPX client session teardowns are explicitly awaited during async client shutdown.Testing & Verification