fix(fireworks): retain root client refs to prevent aiohttp session leak#36202
Open
Mason Daugherty (mdrxy) wants to merge 1 commit intomasterfrom
Open
fix(fireworks): retain root client refs to prevent aiohttp session leak#36202Mason Daugherty (mdrxy) wants to merge 1 commit intomasterfrom
Mason Daugherty (mdrxy) wants to merge 1 commit intomasterfrom
Conversation
`ChatFireworks.validate_environment` extracted `.chat.completions` from freshly created `Fireworks` / `AsyncFireworks` instances and immediately discarded the parents. Starting with `fireworks-ai>=0.19`, those parents eagerly create an `aiohttp.ClientSession` when an async event loop is running. Orphaning the parents means the sessions are never closed, producing "Unclosed client session" warnings at interpreter shutdown. Store parent instances as `root_client` / `root_async_client` (matching the `langchain-openai` pattern) so transports stay reachable and are cleaned up deterministically. Adds a regression test that constructs `ChatFireworks` inside an async context and asserts no `ResourceWarning` about unclosed sessions fires.
Merging this PR will not alter performance
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
ChatFireworks.validate_environmentcreatesFireworks/AsyncFireworksinstances, extracts.chat.completions, and immediately discards the parentsfireworks-ai>=0.19,FireworksClient.__init__eagerly creates anaiohttp.ClientSessionwhen an async event loop is runningUnclosed client sessionwarnings on stderrroot_client/root_async_client(matchinglangchain-openaipattern) so transports stay reachable and are cleaned up by GCReproduction
In an async context (e.g., LangGraph agent, Harbor eval runner):
Additional context
fireworks-aisyncclose()also doesn't clean up the aiohttp session created in async contexts — separate upstream issuefireworks-aipin is bumped to>=0.19; on0.15.xthe aiohttp session isn't created so the test passes vacuously