Skip to content

fix: close child httpx clients in AsyncStream.aclose()#230

Draft
aliev wants to merge 1 commit intomainfrom
fix/close-child-clients-on-aclose
Draft

fix: close child httpx clients in AsyncStream.aclose()#230
aliev wants to merge 1 commit intomainfrom
fix/close-child-clients-on-aclose

Conversation

@aliev
Copy link
Copy Markdown
Member

@aliev aliev commented Mar 27, 2026

Why

AsyncStream.aclose() only closes the main httpx client, but the cached video, chat, and moderation sub-clients each create their own httpx connection pool via @cached_property. When the parent is closed, these child pools remain open, leaking TCP connections.

Discovered during memory leak investigation in vision-agents: after 50 session create+close cycles, 87 orphaned TCP connections remained. This fix (together with vision-agents PR #457) reduced leaked TCP connections from 87 to 5 (-94%).

Changes

  • Override aclose() in AsyncStream to close all cached child httpx clients before closing the main client

AsyncStream.aclose() only closed the main httpx client but not
the cached video/chat/moderation sub-clients, each of which has
its own httpx connection pool. After profiling with 50 session
create+close cycles, 87 orphaned TCP connections remained.

Override aclose() to close all cached child clients before
closing the main client.
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 27, 2026

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: b5d522ea-0a7c-44d5-bd6b-db01d55e51f7

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/close-child-clients-on-aclose

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

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