Skip to content

fix(fireworks): suppress eager aiohttp.ClientSession creation in async contexts#37227

Open
Mohammad Mohtashim (keenborder786) wants to merge 1 commit into
langchain-ai:masterfrom
keenborder786:fix/firework_event_loop
Open

fix(fireworks): suppress eager aiohttp.ClientSession creation in async contexts#37227
Mohammad Mohtashim (keenborder786) wants to merge 1 commit into
langchain-ai:masterfrom
keenborder786:fix/firework_event_loop

Conversation

@keenborder786
Copy link
Copy Markdown
Contributor

Closes #37172

When ChatFireworks is constructed inside a running event loop (e.g. a Jupyter kernel), the Fireworks SDK eagerly opens an aiohttp.ClientSession on each inner client, four per model. Sync invoke never touches them, and they leak as "Unclosed client session" warnings on garbage collection.

A new _suppress_eager_aiohttp_sessions context manager temporarily patches is_running_in_async_context (in both fireworks._util and fireworks.client.api_client) to return False while 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 when asyncio.run can't drive it, removing a secondary "coroutine was never awaited" warning at interpreter shutdown.

A regression test asserts no eager _aiohttp_session is attached to inner clients when constructed inside an event loop.

@github-actions github-actions Bot added fireworks `langchain-fireworks` package issues & PRs fix For PRs that implement a fix integration PR made that is related to a provider partner package integration size: M 200-499 LOC labels May 6, 2026
@langchain-automated-triage langchain-automated-triage Bot added trusted-contributor >= 5 merged PRs in the `langchain-ai/langchain` repo external labels May 6, 2026
@keenborder786 Mohammad Mohtashim (keenborder786) marked this pull request as ready for review May 7, 2026 11:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

external fireworks `langchain-fireworks` package issues & PRs fix For PRs that implement a fix integration PR made that is related to a provider partner package integration size: M 200-499 LOC trusted-contributor >= 5 merged PRs in the `langchain-ai/langchain` repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fireworks client Unclosed client session

1 participant