Repository navigation
colab exec cannot detect a silently dropped websocket: pings are sent but pongs are never checked
#283
kierhodgson-ctrl
started this conversation in
General
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Summary
When the kernel websocket drops without a close (a half-open TCP connection),
colab execdoes not notice. With--timeout 0, or an idle limit longer than the job's quiet periods, the CLI keeps waiting after the remote code has finished, while the runtime keeps billing. Issue #220 covers recovering output after the CLI reportsConnection was lost.; this is the case where the CLI never reports the loss.The cause appears to be that the websocket sends keepalive pings but never checks for the pongs. Setting a ping timeout fixed it in my test.
Reproduction
Environment:
mainat 02d2321 (0.8.1.dev4),jupyter-kernel-client0.8.0,websocket-client1.9.0, Python 3.11, Windows 11, CPU runtime.To get a real half-open connection without touching the CLI, I ran it through a small local HTTP CONNECT proxy (
HTTPS_PROXY=http://127.0.0.1:<port>) that can stop forwarding bytes in both directions while keeping both sockets open.Each case pipes this to
colab exec -s <session>, and the proxy freezes about 8 s after start, onceMARK startedhas been printed:After each case I checked for the receipt file with a fresh, unproxied
colab exec.--timeout 0--timeout(30)TimeoutError: Timeout waiting for output: no message from the kernel for 30sping_timeout=20added (below),--timeout 0RuntimeError: Connection was lost.So today the idle limit is the only thing that catches a dead connection, and jobs with long quiet periods have to raise or disable it.
Case C used the unmodified CLI with one monkeypatch before
colab_cli.cli.main():I only observed case A for 240 s, so "waits indefinitely" is an inference from the code below, not a measurement.
Cause, from the code
jupyter_kernel_client/wsclient.py,_run_websocket:ping_intervaldefaults to 60 andping_timeoutis not passed.websocket-clientonly acts on a missed pong whenping_timeoutis set. The same call is onmainofgooglecolab/jupyter-kernel-clientanddatalayer/jupyter-kernel-client.connection_readyis cleared only in_on_close, which a half-open connection never triggers.colab_cli/runtime.py,_execute_streaming, has two exits for a dead connection:connection_ready, and the--timeoutidle limit. With--timeout 0neither fires.Suggested changes
ping_timeoutso a dead connection closes andexecexits with the existingConnection was lost.error. In case C that took 141 s with a 60 s interval and 20 s timeout; a shorter interval would tighten it.--timeout, so--timeout 0means "no output limit" only.timeout, poll with shortcolab exec --timeout 40calls, and stop the runtime in afinally.Why it matters
This came from a real run: three L4 runtimes driven by long blocking
colab execcalls from a script. The connections dropped silently, no process exited, and the runtimes sat idle for about 4 h 20 min (about 25 compute units) until a person noticed. I did not keep the exact--timeoutvalue of those calls, so the test above is the evidence, not that run.Related: #220 (output lost after a detected disconnect) and #263 (a timed-out
colab newleaves a billing runtime the CLI cannot stop). All three leave metered runtimes running with nothing watching them.Windows note
When the calling script timed out a
uvx ... colabcall and killed it, the childcolabprocess survived and held the output pipes open, so the caller still blocked. Killing the whole tree (taskkill /F /T /PID) was needed. Probablyuvxbehaviour and not a CLI bug, but worth a line in the Windows notes.I can share the proxy and runner scripts (about 200 lines) if useful.
All reactions