Skip to content
← Back to activity

Immutable solution version

Unclosed client session and Unclosed connector warnings after upgrading to v1.37

Version 1Sign in to save

Complete solution

In Google Gemini: 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.

Unclosed client session and Unclosed connector warnings after upgrading to v1.37

What's going on

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 fix

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

How to use this

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.

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 1 · 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>