Commit ee3d72a
fix(sync): fail fast instead of spinning at 100% CPU when the dispatcher fiber dies
When the driver connection ends without going through Connection.cleanup()
- e.g. the driver process dies, or a remote CDP connection wedges and the
transport takes the silent IncompleteReadError path - the dispatcher fiber
finishes with sync calls still pending. Their tasks can never complete, and
because switching to a dead greenlet returns immediately to its parent, the
waiting loop in SyncBase._sync degenerates into a pure userspace busy-loop:
the thread pins one core, holds the GIL, and neither raises nor logs.
Observed in production via strace (100% futex, zero IO syscalls) with py-spy
showing threads stopped on the same _sync line for the process lifetime.
Detect the dead dispatcher inside the waiting loop and raise
TargetClosedError instead. A dead fiber can never complete the task, so
raising there is always correct.
The regression test recreates the failure end to end: kill the driver on the
silent path, then make one more sync call. Without the fix the call spins
forever (the subprocess times out); with it, it raises promptly.
Co-authored-by: Claude <noreply@anthropic.com>1 parent 010a9cc commit ee3d72a
2 files changed
Lines changed: 53 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
| 35 | + | |
35 | 36 | | |
36 | 37 | | |
37 | 38 | | |
| |||
110 | 111 | | |
111 | 112 | | |
112 | 113 | | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
113 | 125 | | |
114 | 126 | | |
115 | 127 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
399 | 399 | | |
400 | 400 | | |
401 | 401 | | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
402 | 443 | | |
403 | 444 | | |
404 | 445 | | |
0 commit comments