You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix(python-sdk): key async transport caches by loop object, not id(loop) (#1434)
## Description
The per-event-loop caches for `AsyncHTTPTransport`s and
`httpx.AsyncClient`s (Sandbox API, envd, and volume clients) were keyed
by `id(asyncio.get_running_loop())`, but CPython reuses object ids of
dead loops almost immediately — so sequential loops could inherit a
transport bound to a previous, closed loop and fail. The caches are now
`weakref.WeakKeyDictionary`s keyed by the loop object itself, which
makes stale id collisions impossible and releases entries when their
loop is garbage collected (fixing a leak where dead-loop entries
accumulated forever). Added regression tests covering the
sequential-loop scenario for all three caches.
This pattern no longer breaks:
```python
# e.g. a worker or test harness running repeated event loops
for job in jobs:
asyncio.run(process_with_sandbox(job)) # each run previously risked
# inheriting a closed loop's transport
```
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
Key per-event-loop async HTTP transport and client caches by the loop object (held weakly) instead of `id(loop)`. CPython can reuse the id of a closed loop almost immediately, so sequential event loops (for example repeated `asyncio.run(...)` calls) could inherit a transport or client bound to a previous, closed loop. Cache entries are now also released automatically when their loop is garbage collected.
0 commit comments