Skip to content

Job never completes: AppendLiveConsoleFeedAsync spins forever when a concurrent websocket reconnect clears _websocketClient #4767

Open

Description

@SchwarzschildX

[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):

  1. When a send fails, the retry loop in AppendLiveConsoleFeedAsync calls InitializeWebsocketClient once per retry. Each call starts a ConnectWebSocketClient task that it does not await. Three reconnects then run at once, and all of them use the shared _websocketClient field.

  2. ConnectWebSocketClient connects whatever client the field holds, not one it created. If that fails, its catch disposes the field's client and sets it to null (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., then ObjectDisposedException in ConnectAsyncCore). It can also dispose and clear a client that a later attempt has already connected and published.

  3. The next AppendLiveConsoleFeedAsync call awaits only the last reconnect task (_websocketConnectTask). Earlier attempts are still running. The outer if (_websocketClient != null) check passes, and then a late attempt's catch sets the field to null. This can happen during an earlier chunk's SendAsync.

  4. In the send loop, a null field 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 delivered nor retries changes, 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, so ShutdownAsync never 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:

  • ConnectWebSocketClient creates and connects its own client. It publishes the client to _websocketClient only after connecting, and on failure disposes only that client.
  • AppendLiveConsoleFeedAsync reads _websocketClient once 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.ShutdownAsync gives 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

  1. winckler commented on Oct 15, 2026

    @winckler

    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 was Fire signal to shutdown all queues., with no All queue process task stopped. after it. The listener kept renewing the job every minute and never logged Worker 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:

    [WORKER 2026-10-14 14:07:50Z INFO JobRunner] Job result after all job steps finish: Succeeded
    [WORKER 2026-10-14 14:07:50Z INFO JobRunner] Shutting down the job server queue.
    [WORKER 2026-10-14 14:07:50Z INFO JobServerQueue] Fire signal to shutdown all queues.
    [RUNNER 2026-10-14 14:08:03Z INFO JobDispatcher] Successfully renew job <id>, job is valid till 10/14/2026 2:18:03 PM
    [RUNNER 2026-10-14 14:09:03Z INFO JobDispatcher] Successfully renew job <id>, job is valid till 10/14/2026 2:19:03 PM
    (...)
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions