Dispose and fully restart the WS client if it's choking due to TaskCanceledException

This commit is contained in:
barelyprofessional
2026-05-31 10:31:49 -05:00
parent 17d2e0415a
commit 3ae74c0fbf
2 changed files with 14 additions and 1 deletions
+8 -1
View File
@@ -162,7 +162,7 @@ public class ChatBot
{ {
// Yeah, super dodgy // Yeah, super dodgy
KfClient.LastPacketReceived = DateTime.UtcNow; KfClient.LastPacketReceived = DateTime.UtcNow;
_logger.Error("Forcing disconnect and restart as bot is completely dead"); _logger.Error("Forcing reconnect as bot is completely dead");
await KfClient.ReconnectAsync(); await KfClient.ReconnectAsync();
} }
} }
@@ -857,6 +857,13 @@ public class ChatBot
_logger.Info("Reconnecting"); _logger.Info("Reconnecting");
KfClient.ReconnectAsync().Wait(_cancellationToken); KfClient.ReconnectAsync().Wait(_cancellationToken);
} }
if (disconnectionInfo.Exception is TaskCanceledException)
{
_logger.Error("WebSocket client is broken as the cancellation token it held onto is FUCKING DEAD. Going to dispose and restart the WS client");
KfClient.DisposeWsClient();
KfClient.StartWsClient().Wait(_cancellationToken);
}
} }
private void OnKfWsReconnected(object sender, ReconnectionInfo reconnectionInfo) private void OnKfWsReconnected(object sender, ReconnectionInfo reconnectionInfo)
+6
View File
@@ -114,6 +114,12 @@ public class ChatClient
_logger.Debug("Websocket client started!"); _logger.Debug("Websocket client started!");
} }
public void DisposeWsClient()
{
if (_wsClient == null) throw new WebSocketNotInitializedException();
_wsClient.Dispose();
}
public bool IsConnected() public bool IsConnected()
{ {
return _wsClient is { IsRunning: true }; return _wsClient is { IsRunning: true };