diff --git a/src/Runner.Common/JobServer.cs b/src/Runner.Common/JobServer.cs index 98cf88f923e..93429d90308 100644 --- a/src/Runner.Common/JobServer.cs +++ b/src/Runner.Common/JobServer.cs @@ -143,8 +143,18 @@ public void InitializeWebsocketClient(ServiceEndpoint serviceEndpoint) public ValueTask DisposeAsync() { - _websocketClient?.CloseOutputAsync(WebSocketCloseStatus.NormalClosure, "Shutdown", CancellationToken.None); + try + { + _websocketClient?.CloseOutputAsync(WebSocketCloseStatus.NormalClosure, "Shutdown", CancellationToken.None); + } + catch (Exception ex) + { + // In some cases this might be okay since the websocket might be open yet, so just close and don't trace exceptions + Trace.Info($"Failed to close websocket gracefully {ex.GetType().Name}"); + } + GC.SuppressFinalize(this); + return ValueTask.CompletedTask; }