What this thread does
RuntimeError: Event loop is closed — check whether one async client spans successive asyncio.run() calls. APIConnectionError: [Errno 9] Bad file descriptor — check whether an Interactions call fails immediately despite configured retries.
The loop report alternates failures and successes as stale pooled connections are discarded. The Interactions report concerns retry handling, not an established shared cause.
First actions: keep client creation, use and cleanup inside async with genai.Client().aio as client: within one top-level asyncio.run(main()). For Interactions, record python -m pip show google-genai httpx aiohttp, then count attempts with #3204's mock-transport reproduction; no confirmed repair command is established.
Evidence: two issue reports include a maintainer reproduction of the loop error and acknowledgement of the retry report. The lifecycle adaptation and retry reproduction are untested; the loop fix is now released, while the original descriptor-failure cause remains unconfirmed.
Not for: Gemini request data retention.
What changed
- google-genai #3157, reported 2026-10-17 (checked 2026-11-17), describes alternating failures when one async HTTP client spans successive event loops; it closed on 2026-11-14 through merged PR #3282. As of November 2026, google-genai 3.4.0, released 2026-11-16, includes the per-event-loop HTTPX connection-pool fix.
- google-genai #3204, reported 2026-10-23 (checked 2026-11-17), describes Interactions connection failures escaping the configured retries. A maintainer acknowledged the report; its proposed fix, PR #3205, remains open and unmerged.
How to migrate
1. Record the actual packages and identify whether the failing call uses models or interactions.
python -m pip show google-genai httpx aiohttp
2. For repeated asyncio.run() calls sharing one client, move creation, use and cleanup inside a single top-level coroutine. Python's runner docs say asyncio.run() closes its loop and should ideally be called once (checked 2026-10-28). Google's client context-manager docs show automatic async cleanup (checked 2026-10-28).
import asyncio
from google import genai
async def main():
async with genai.Client().aio as client:
# Await your existing calls here, using this client.
# Keep your currently configured model and request arguments.
pass
asyncio.run(main())
This lifecycle workaround follows those docs; it is not an upstream patch. In an async web framework, use the framework's running loop and matching client shutdown instead of nesting asyncio.run().
3. For Interactions failing immediately despite retry options, use the mock-transport reproduction linked in #3204 and count attempts without a live request. The report establishes no confirmed repair command for that defect; PR #3205 remains open (checked 2026-11-17). Check its linked fix before choosing an upgrade; changing retry counts alone is not demonstrated to solve it.
What breaks
Diagnostic: RuntimeError: Event loop is closed
In #3157's reproduction, pooled connections belong to a loop that a previous asyncio.run() closed. The next call reuses a stale connection; a later call can succeed after it is discarded. Installing the optional async transport is not a general Interactions remedy: the report says that layer still uses the HTTPX client.
Diagnostic: APIConnectionError: [Errno 9] Bad file descriptor
In #3204, a production Interactions call surfaces this immediately. The mock reproduction explains the missing retries: an error hook wraps the transport exception before the retry classifier sees it. That does not establish the original operating-system descriptor failure's cause. Do not assume it is the same bug as cross-loop reuse.
What to test
- Run several calls within one loop, including the same API surface that failed, and close the client before loop shutdown.
- Check test-fixture scope matches the async client's loop scope.
- In the Interactions mock reproduction, compare transport-failure and retryable-status attempt counts. Assert the intended budget rather than inferring it from the option name.
Pitfalls
Do not close a shared client while other requests still use it. Do not add unlimited retries to a broken lifetime. Before adding an application retry around Interactions, establish whether repeating that operation can create duplicate work; the issue provides no universal safe retry recipe.
A prompt to give your agent
Your training data predates #3157 and #3204. Read them and Google's current client-lifecycle documentation. Trace client creation, loop ownership and cleanup. Separate the lifecycle change from retry handling. Keep the existing configured model; do not guess a model ID or a fixed SDK release.
Limits
The lifecycle adaptation and retry reproduction are untested. Evidence is two issue reports, including a maintainer reproduction of the loop error. The descriptor failure's original cause remains unconfirmed in #3204; the loop fix is now released (checked 2026-11-17).
Started from a post by @AtulJoshi1206, packaged by the editor. Original post