Commit 24e9c32
Cancel-and-detach prior pending_drain on _invalidate; clear cause on close; guard create_task on closed loop
Three client-side cleanup follow-ups:
- ``_invalidate`` overwrote ``self._pending_drain`` with a fresh
bounded-drain task whenever it fired. If a prior _invalidate had
already published one, that orphan kept running but was no
longer reachable through ``self`` — close() awaited only the
second task, and the first triggered "Task was destroyed but it
is pending" at GC, recreating the exact warning ``_pending_drain``
was added to suppress. Cancel-and-detach the prior task before
the assignment, mirroring ``connect()``'s pending-retire idiom.
- ``_invalidate``'s ``loop.create_task(_bounded_drain())`` was
unguarded against ``RuntimeError("Event loop is closed")`` —
realistic during interpreter shutdown / engine.dispose() races.
The unhandled raise replaced the original cancel/cause that
drove invalidation, breaking SA's is_disconnect substring
classifier downstream. Wrap the create_task in try/except
RuntimeError, log debug, leave _pending_drain as None.
- ``_close_impl`` did not clear ``self._invalidation_cause``. The
cached exception holds a traceback chain (frames + locals +
globals) that pinned a large object graph across close →
re-connect cycles, even though every other piece of post-failure
state was scrubbed. Add the one-line clear to the existing
scrub block.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent e3a2ab3 commit 24e9c32
1 file changed
Lines changed: 36 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1247 | 1247 | | |
1248 | 1248 | | |
1249 | 1249 | | |
| 1250 | + | |
| 1251 | + | |
| 1252 | + | |
| 1253 | + | |
| 1254 | + | |
| 1255 | + | |
| 1256 | + | |
1250 | 1257 | | |
1251 | 1258 | | |
1252 | 1259 | | |
| |||
1431 | 1438 | | |
1432 | 1439 | | |
1433 | 1440 | | |
| 1441 | + | |
| 1442 | + | |
| 1443 | + | |
| 1444 | + | |
| 1445 | + | |
| 1446 | + | |
| 1447 | + | |
| 1448 | + | |
| 1449 | + | |
| 1450 | + | |
| 1451 | + | |
| 1452 | + | |
1434 | 1453 | | |
1435 | 1454 | | |
1436 | | - | |
| 1455 | + | |
| 1456 | + | |
| 1457 | + | |
| 1458 | + | |
| 1459 | + | |
| 1460 | + | |
| 1461 | + | |
| 1462 | + | |
| 1463 | + | |
| 1464 | + | |
| 1465 | + | |
| 1466 | + | |
| 1467 | + | |
| 1468 | + | |
| 1469 | + | |
| 1470 | + | |
| 1471 | + | |
1437 | 1472 | | |
1438 | 1473 | | |
1439 | 1474 | | |
| |||
0 commit comments