fix(fireworks): suppress eager aiohttp.ClientSession creation in async contexts#37227
Open
Mohammad Mohtashim (keenborder786) wants to merge 1 commit into
Open
Conversation
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.
Closes #37172
When
ChatFireworksis constructed inside a running event loop (e.g. a Jupyter kernel), the Fireworks SDK eagerly opens anaiohttp.ClientSessionon each inner client, four per model. Syncinvokenever touches them, and they leak as "Unclosed client session" warnings on garbage collection.A new
_suppress_eager_aiohttp_sessionscontext manager temporarily patchesis_running_in_async_context(in bothfireworks._utilandfireworks.client.api_client) to returnFalsewhile the SDK clients are constructed, then restores the originals. Async-non-streaming still works because the SDK lazily recreates the session on first use.Also tightens
__del__to explicitly close the fallback_close_async()coroutine whenasyncio.runcan't drive it, removing a secondary "coroutine was never awaited" warning at interpreter shutdown.A regression test asserts no eager
_aiohttp_sessionis attached to inner clients when constructed inside an event loop.