Skip to content

Commit

Permalink
fix: Add a bottom try-catch to catch websocket errors
Browse files Browse the repository at this point in the history
  • Loading branch information
lynzrand committed Nov 29, 2021
1 parent 7de0907 commit 86f746c
Showing 1 changed file with 23 additions and 19 deletions.
42 changes: 23 additions & 19 deletions coordinator/Services/JudgerCoordinatorService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -157,25 +157,29 @@ public async ValueTask<bool> TryUseConnection(HttpContext ctx) {

IDisposable AssignObservables(string clientId, JudgerWebsocketWrapperTy client) {
return client.Messages.Subscribe((msg) => {
logger.LogTrace($"Judger {clientId} sent message of type {msg.GetType().Name}");
switch (msg) {
case JobResultMsg msg1:
OnJobResultMessage(clientId, msg1); break;
case JobProgressMsg msg1:
OnJobProgressMessage(clientId, msg1); break;
case PartialResultMsg msg1:
OnPartialResultMessage(clientId, msg1); break;
case ClientStatusMsg msg1:
OnJudgerStatusUpdateMessage(clientId, msg1); break;
case JobRequestMsg msg1:
OnJobRequestMessage(clientId, msg1); break;
case JobOutputMsg msg1:
OnJobOutputMessage(clientId, msg1); break;
case RevertJobMsg msg1:
OnRevertJobMessage(clientId, msg1); break;
default:
logger.LogCritical("Unable to handle message type {0}", msg.GetType().Name);
break;
try {
logger.LogTrace($"Judger {clientId} sent message of type {msg.GetType().Name}");
switch (msg) {
case JobResultMsg msg1:
OnJobResultMessage(clientId, msg1); break;
case JobProgressMsg msg1:
OnJobProgressMessage(clientId, msg1); break;
case PartialResultMsg msg1:
OnPartialResultMessage(clientId, msg1); break;
case ClientStatusMsg msg1:
OnJudgerStatusUpdateMessage(clientId, msg1); break;
case JobRequestMsg msg1:
OnJobRequestMessage(clientId, msg1); break;
case JobOutputMsg msg1:
OnJobOutputMessage(clientId, msg1); break;
case RevertJobMsg msg1:
OnRevertJobMessage(clientId, msg1); break;
default:
logger.LogCritical("Unable to handle message type {0}", msg.GetType().Name);
break;
}
} catch (Exception e) {
logger.LogError(e.ToString());
}
}, _ => { }, () => {
logger.LogInformation($"Judger {clientId} finished connection");
Expand Down

0 comments on commit 86f746c

Please sign in to comment.