Repository navigation
Description
[claude-opus-5-5] RESPONDING ON BEHALF OF @SchwarzschildX
Describe the bug
A job whose steps had all finished stayed in_progress for 56 minutes, until it was cancelled by hand. The worker logged Fire signal to shutdown all queues. and never logged All queue process task stopped.. JobServerQueue.ShutdownAsync waits without a bound for the live-console dequeue task, and that task was stuck in ResultServer.AppendLiveConsoleFeedAsync. So the worker never called CompleteJobAsync, and the job's result was never reported.
The cause is in src/Runner.Common/ResultsServer.cs (the same code in v2.337.0, v2.338.0 and main at 67f01c2):
-
When a send fails, the retry loop in
AppendLiveConsoleFeedAsynccallsInitializeWebsocketClientonce per retry. Each call starts aConnectWebSocketClienttask that it does not await. Three reconnects then run at once, and all of them use the shared_websocketClientfield. -
ConnectWebSocketClientconnects whatever client the field holds, not one it created. If that fails, itscatchdisposes the field's client and sets it tonull(this._websocketClient?.Dispose(); this._websocketClient = null;, added in Fix null ref exception when websocket client retries. #4589). So one attempt disposes a client that another attempt is connecting (The WebSocket has already been started., thenObjectDisposedExceptioninConnectAsyncCore). It can also dispose and clear a client that a later attempt has already connected and published. -
The next
AppendLiveConsoleFeedAsynccall awaits only the last reconnect task (_websocketConnectTask). Earlier attempts are still running. The outerif (_websocketClient != null)check passes, and then a late attempt'scatchsets the field tonull. This can happen during an earlier chunk'sSendAsync. -
In the send loop, a
nullfield means no work is done:while (!delivered && retries < 3) { try { if (_websocketClient != null) // null: no send, no exception, retries unchanged { await _websocketClient.SendAsync(...); delivered = true; } } catch (Exception ex) { retries++; InitializeWebsocketClient(...); } }
Neither
deliverednorretrieschanges, and nothing is awaited, so the loop spins forever on a thread-pool thread. The 60-second cancellation token of the batch is never checked. The live-console dequeue task never finishes, soShutdownAsyncnever returns.
To Reproduce
The window is narrow, so I have no deterministic reproduction. It needs a live-console websocket send to fail while the job writes output. Across 765 worker logs from five Linux runners over two weeks, 44 show the reconnect exceptions, and one job hung. In every other case, live-console appends continued after the exceptions.
Expected behavior
A failed live-console send or reconnect never blocks job completion. The worker reports the job's result shortly after the last step. The live console is best effort, and the step and job logs are uploaded through the results upload queue anyway.
Runner Version and Platform
2.337.0, Linux x64, self-hosted, repository-scoped. The runner is built from the v2.337.0 tag by nixpkgs. nixpkgs' patches do not touch Runner.Common's ResultsServer.cs or JobServerQueue.cs. 2.338.0 and main contain the same code.
What's not working?
The job remains in_progress after its last step (Complete runner / Complete job) has finished. Jobs that share its concurrency group cannot start until it is cancelled or reaches its job timeout.
Runner and Worker's Diagnostic Logs
Worker log, UTC:
[2026-10-07 20:14:48Z INFO ResultServer] Websocket is not open, let's attempt to connect back again with random backoff 00:00:00.3080000 ms.
[2026-10-07 20:14:51Z INFO ResultServer] Creating websocket client ...wss://results-receiver.actions.githubusercontent.com/_ws/ingest.sock
[2026-10-07 20:14:51Z INFO ResultServer] Attempting to start websocket client with delay 00:00:00.3080000.
[2026-10-07 20:14:51Z INFO ResultServer] Websocket is not open, let's attempt to connect back again with random backoff 00:00:00.1440000 ms.
[2026-10-07 20:14:51Z INFO ResultServer] Creating websocket client ...wss://results-receiver.actions.githubusercontent.com/_ws/ingest.sock
[2026-10-07 20:14:51Z INFO ResultServer] Attempting to start websocket client with delay 00:00:00.1440000.
[2026-10-07 20:14:51Z INFO ResultServer] Websocket is not open, let's attempt to connect back again with random backoff 00:00:00.2940000 ms.
[2026-10-07 20:14:51Z INFO ResultServer] Creating websocket client ...wss://results-receiver.actions.githubusercontent.com/_ws/ingest.sock
[2026-10-07 20:14:51Z INFO ResultServer] Attempting to start websocket client with delay 00:00:00.2940000.
[2026-10-07 20:14:51Z INFO JobServerQueue] Try to append 1 batches web console lines for record '68f7a0a4-…', success rate: 1/1.
[2026-10-07 20:14:51Z INFO ResultServer] Exception caught during websocket client connect, retry connection.
[2026-10-07 20:14:52Z ERR ResultServer] System.InvalidOperationException: The WebSocket has already been started.
at System.Net.WebSockets.ClientWebSocket.ConnectAsync(Uri uri, HttpMessageInvoker invoker, CancellationToken cancellationToken)
at GitHub.Runner.Common.ResultServer.ConnectWebSocketClient(String feedStreamUrl, TimeSpan delay, Boolean retryConnection) in /_/src/Runner.Common/ResultsServer.cs:line 206
[2026-10-07 20:14:54Z INFO ResultServer] Successfully started websocket client.
[2026-10-07 20:14:54Z INFO ResultServer] Exception caught during websocket client connect, retry connection.
[2026-10-07 20:14:54Z ERR ResultServer] System.ObjectDisposedException: Cannot access a disposed object.
Object name: 'System.Net.WebSockets.ClientWebSocket'.
at System.Net.WebSockets.ClientWebSocket.ConnectAsyncCore(Uri uri, HttpMessageInvoker invoker, CancellationToken cancellationToken)
at GitHub.Runner.Common.ResultServer.ConnectWebSocketClient(String feedStreamUrl, TimeSpan delay, Boolean retryConnection) in /_/src/Runner.Common/ResultsServer.cs:line 206
… the step and three later steps write output and finish; results uploads continue
… ("Tried to upload 2 file(s) to results, success rate: 2/2."), but there is no further
… "web console lines" entry for the rest of the job …
[2026-10-07 20:22:46Z INFO JobRunner] Job result after all job steps finish: Failed
[2026-10-07 20:22:46Z INFO JobRunner] Completing the job execution context.
[2026-10-07 20:22:46Z INFO JobRunner] Shutting down the job server queue.
[2026-10-07 20:22:46Z INFO JobServerQueue] Fire signal to shutdown all queues.
[2026-10-07 21:19:02Z INFO ProcessChannel] Receiving message of length 0, with hash 'e3b0c442…'
[2026-10-07 21:19:02Z INFO Worker] Cancellation/Shutdown message received.
A normal shutdown logs All queue process task stopped. about one second after Fire signal to shutdown all queues.. The listener kept renewing the job request every minute until the manual cancellation.
Suggested fix
We are rolling out this patch on our runners. The full L0 suite passes with it, including new tests for both changes:
ConnectWebSocketClientcreates and connects its own client. It publishes the client to_websocketClientonly after connecting, and on failure disposes only that client.AppendLiveConsoleFeedAsyncreads_websocketClientonce and sends every chunk on that client. On failure it clears the field, disposes its own client and starts exactly one reconnect, which the next call awaits. It does not resend the rest of a message on another connection.JobServerQueue.ShutdownAsyncgives the best-effort live console one 2-minute deadline, covering both its dequeue task and its final drain. If the deadline passes, it logs a warning, skips the remaining live-console lines, and continues to upload logs and complete the job.
@@ ResultsServer.InitializeWebsocketClient
Trace.Info($"Creating websocket client ..." + liveConsoleFeedUrl);
- this._websocketClient = CreateWebSocketClient();
// during initialization, retry upto 3 times to setup connection
this._websocketConnectTask = ConnectWebSocketClient(liveConsoleFeedUrl, delay, retryConnection);
@@ ResultsServer.ConnectWebSocketClient
do
{
+ var websocketClient = CreateWebSocketClient();
try
{
Trace.Info($"Attempting to start websocket client with delay {delay}.");
await Task.Delay(delay);
using (var connectTimeoutTokenSource = new CancellationTokenSource(TimeSpan.FromSeconds(30)))
{
- if (this._websocketClient == null)
- {
- this._websocketClient = CreateWebSocketClient();
- }
-
- await this._websocketClient.ConnectAsync(new Uri(feedStreamUrl), connectTimeoutTokenSource.Token);
+ await websocketClient.ConnectAsync(new Uri(feedStreamUrl), connectTimeoutTokenSource.Token);
}
+ this._websocketClient = websocketClient;
Trace.Info($"Successfully started websocket client.");
connected = true;
}
catch (Exception ex)
{
...
retries++;
- this._websocketClient?.Dispose();
- this._websocketClient = null;
+ websocketClient.Dispose();
_lastConnectionFailure = DateTime.Now;
}
@@ ResultsServer.AppendLiveConsoleFeedAsync
- if (_websocketClient != null)
+ var websocketClient = _websocketClient;
+ if (websocketClient != null)
{
...
- for (...)
- {
- ...
- delivered = false;
- while (!delivered && retries < 3)
- {
- try
- {
- if (_websocketClient != null)
- {
- await _websocketClient.SendAsync(chunk, WebSocketMessageType.Text, endOfMessage: lastChunk, cancellationToken);
- delivered = true;
- }
- }
- catch (Exception ex)
- {
- ...
- retries++;
- InitializeWebsocketClient(_liveConsoleFeedUrl, delay);
- }
- }
- }
+ try
+ {
+ for (...)
+ {
+ ...
+ await websocketClient.SendAsync(chunk, WebSocketMessageType.Text, endOfMessage: lastChunk, cancellationToken);
+ }
+
+ delivered = true;
+ }
+ catch (Exception ex)
+ {
+ ...
+ _websocketClient = null;
+ websocketClient.Dispose();
+ InitializeWebsocketClient(_liveConsoleFeedUrl, delay);
+ }
}
-
- if (!delivered)
- {
- // Giving up for now, so next invocation of this method won't attempt to reconnect
- _websocketClient = null;
-
- // however if 10 minutes have already passed, let's try reestablish connection again
- if (_lastConnectionFailure.HasValue && DateTime.Now > _lastConnectionFailure.Value.AddMinutes(10))
- {
- InitializeWebsocketClient(_liveConsoleFeedUrl, TimeSpan.Zero);
- }
- }
+ else if (_lastConnectionFailure.HasValue && DateTime.Now > _lastConnectionFailure.Value.AddMinutes(10))
+ {
+ InitializeWebsocketClient(_liveConsoleFeedUrl, TimeSpan.Zero);
+ }
Activity
winckler commentedon Oct 15, 2026
To add a data point, we hit what looks like the same hang on a self-hosted macOS runner: runner 2.338.0 (osx-arm64) in an ephemeral macOS 26.6.2 Tart VM. Every step finished and reported
Succeeded. The worker's last line wasFire signal to shutdown all queues., with noAll queue process task stopped.after it. The listener kept renewing the job every minute and never loggedWorker finished, so the job stayed in_progress until I cancelled it. I don't have the Worker_.log, so I can't confirm the earlier websocket reconnect exceptions, but the shutdown signature matches: