Repository navigation
colab exec: when the kernel websocket takes more than 10 s to connect, the code is never sent and the CLI hangs after "Connection was lost." #264
dreaifekks
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.
Versions: google-colab-cli 0.8.0 (the relevant code is unchanged on main 0abf82d), jupyter-kernel-client 0.9.0, websocket-client 1.9.2, Python 3.12, Linux client, L4 runtimes.
What happens
On 2026-11-19, 9
colab execcalls failed the same way: the code never ran on the VM (the kernel stayed idle), the CLI printedConnection was lost., and then the process did not exit until our outertimeoutkilled it. One call with--timeout 0hung for about 71 minutes and used about 1.8 compute units for nothing.From the debug log (times only), in the three failures I looked at closely:
Cause (from reading the code)
start_channels()in jupyter-kernel-client waits forconnection_readyfor at mostREQUEST_TIMEOUTseconds (10 by default) and returns without an error when that wait times out.execthen runs the/contentprelude (commands/execution.py:223-235). The execute request goes out before the websocket is connected and is lost, so_execute_streamingraisesRuntimeError("Connection was lost.")(runtime.py:305).try/exceptthat re-raises without callingruntime.stop(). Thetry/finallythat callsruntime.stop()starts after it. The websocket thread is not a daemon thread, so once the handshake completes it keeps pinging and the interpreter waits for it.colab runhas the same prelude inside itstry/finally(commands/run.py:411-461), so it exits.replhas the same pattern asexec(commands/execution.py:326).Possible fix
execandreplinside thetry/finallythat callsruntime.stop(), asrundoes.connection_readyis set (or wait longer for it), and fail with a clear error before sending any request.This is different from #220, where the connection drops while the code is already running. #221 adds
runtime.stop()to the prelude'sexcept, which would stop the hang but not the lost request. #261 waits for a reconnect, but here the request has already been sent before the handshake completed.All reactions