FeedStream: handle websocket close failures (#1789)

* handle close failures

* handle in other place as well

* refactor

* bump runner version

* update release notes
This commit is contained in:
Yashwanth Anantharaju
2022-03-28 14:41:21 -04:00
committed by GitHub
parent 2e3976cf97
commit 909b05eb66
3 changed files with 20 additions and 8 deletions

View File

@@ -1,11 +1,7 @@
## Features ## Features
## Bugs ## Bugs
- Fixed a crash on runner startup (#1770) - Fixed an issue where websockets failed to successfully close when posting log lines (#1790)
## Misc
- Clarified the type of step running when running job started or completed hooks (#1769)
## Windows x64 ## Windows x64

View File

@@ -146,8 +146,10 @@ namespace GitHub.Runner.Common
public ValueTask DisposeAsync() public ValueTask DisposeAsync()
{ {
_websocketClient?.CloseOutputAsync(WebSocketCloseStatus.NormalClosure, "Shutdown", CancellationToken.None); CloseWebSocket(WebSocketCloseStatus.NormalClosure, CancellationToken.None);
GC.SuppressFinalize(this); GC.SuppressFinalize(this);
return ValueTask.CompletedTask; return ValueTask.CompletedTask;
} }
@@ -256,7 +258,8 @@ namespace GitHub.Runner.Common
if (failedAttemptsToPostBatchedLinesByWebsocket * 100 / totalBatchedLinesAttemptedByWebsocket > _minWebsocketFailurePercentageAllowed) if (failedAttemptsToPostBatchedLinesByWebsocket * 100 / totalBatchedLinesAttemptedByWebsocket > _minWebsocketFailurePercentageAllowed)
{ {
Trace.Info($"Exhausted websocket allowed retries, we will not attempt websocket connection for this job to post lines again."); Trace.Info($"Exhausted websocket allowed retries, we will not attempt websocket connection for this job to post lines again.");
_websocketClient?.CloseOutputAsync(WebSocketCloseStatus.InternalServerError, "Shutdown due to failures", cancellationToken); CloseWebSocket(WebSocketCloseStatus.InternalServerError, cancellationToken);
// By setting it to null, we will ensure that we never try websocket path again for this job // By setting it to null, we will ensure that we never try websocket path again for this job
_websocketClient = null; _websocketClient = null;
} }
@@ -284,6 +287,19 @@ namespace GitHub.Runner.Common
} }
} }
private void CloseWebSocket(WebSocketCloseStatus closeStatus, CancellationToken cancellationToken)
{
try
{
_websocketClient?.CloseOutputAsync(closeStatus, "Closing websocket", cancellationToken);
}
catch (Exception websocketEx)
{
// 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 {websocketEx.GetType().Name}");
}
}
public Task<TaskAttachment> CreateAttachmentAsync(Guid scopeIdentifier, string hubName, Guid planId, Guid timelineId, Guid timelineRecordId, string type, string name, Stream uploadStream, CancellationToken cancellationToken) public Task<TaskAttachment> CreateAttachmentAsync(Guid scopeIdentifier, string hubName, Guid planId, Guid timelineId, Guid timelineRecordId, string type, string name, Stream uploadStream, CancellationToken cancellationToken)
{ {
CheckConnection(); CheckConnection();

View File

@@ -1 +1 @@
2.289.1 2.289.2