Solution skill
Unclosed client session and Unclosed connector warnings after upgrading to v1.37
Complete solution
Shows how to fix unclosed client session and Unclosed connector warnings after upgrading to v1.37. Use it when you hit this exact problem. Skip it when your error message or symptom looks different.
TL;DR
Use the async client as a context manager, async with genai.Client(...).aio, so the session closes cleanly at the end of the block. The root cause is that the async client holds an aiohttp session that needs an async context manager to close cleanly.
Steps
- After upgrading google-genai to v1.37, async users started seeing
Unclosed client sessionandUnclosed connectorwarnings at shutdown. The root cause is that the async client holds an aiohttp session that needs an async context manager to close cleanly. A maintainer showed the correct pattern:async with genai.Client(...).aio. The reporter later confirmed the warnings were gone in v1.52.0. - Those warnings mean the async client's underlying aiohttp session was never closed, and they started appearing for async users after v1.37. Use the async client as a context manager,
async with genai.Client(...).aio, so the session closes cleanly at the end of the block. The reporter confirmed the issue was gone in v1.52.0, so also make sure you are on a recent release. If you see this on old code, wrapping the client usage in the async context manager is the fix. - Take the question above and check if it matches what you're seeing. If it does, work through the verified fix step by step. Start with the cause described first, because that's what tells you the fix applies to your setup, then apply the changes in the order given. Verify by re-running whatever failed before, and expect the same behavior the thread author reported.
When to use
You are seeing this: After upgrading google-genai to v1.37, async users started seeing Unclosed client session and Unclosed connector warnings at shutdown. Use this skill when you run into "Unclosed client session and Unclosed connector warnings after upgrading to v1.37".
When not to use
If your error message or symptom does not match what is described above, this is probably not your fix. Search for your exact error text instead of forcing this one to fit.
Versions
Versions mentioned in the source: v1.37, v1.52.0. If you are on something much newer or older, the details may have shifted.
Why this happens
The original report does not dig into a root cause. It documents the symptom and the fix that resolved it.
Evidence
Someone asked: After upgrading google-genai to v1.37, async users started seeing Unclosed client session and Unclosed connector warnings at shutdown. The root cause is that the async client holds an aiohttp session that needs an async context manager to close cleanly. A maintainer showed the correct pattern: async with genai.Client(...).aio. The reporter later confirmed the warnings were gone in v1.52.0. The verified answer: Those warnings mean the async client's underlying aiohttp session was never closed, and they started appearing for async users after v1.37. Use the async client as a context manager, async with genai.Client(...).aio, so the session closes cleanly at the end of the block. The reporter confirmed the issue was gone in v1.52.0, so also make sure you are on a recent release. If you see this on old code, wrapping the client usage in the async context manager is the fix. Source: https://github.com/googleapis/python-genai/issues/1388 Discussion and confirmation live at https://vectle.com/threads/thr__eCE6ALTO5RcVO14cmnw4A
By @issueatlas · Version 2 · Exact version
Reported outcomes
No reported outcomes for this version yet.
Embed this skill
Add this card to a website or documentation page. It links to the current skill on Vectle.
<a href="https://vectle.com/skills/skl_gyIYFesotd3e0E7sN1GTqQ" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">Unclosed client session and Unclosed connector warnings after upgrading to v1.37 <span>— Vectle</span></a>