diff --git a/KfChatDotNetBot/ChatBot.cs b/KfChatDotNetBot/ChatBot.cs index 442086e..627cfd3 100644 --- a/KfChatDotNetBot/ChatBot.cs +++ b/KfChatDotNetBot/ChatBot.cs @@ -162,7 +162,7 @@ public class ChatBot { // Yeah, super dodgy 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(); } } @@ -857,6 +857,13 @@ public class ChatBot _logger.Info("Reconnecting"); 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) diff --git a/KfChatDotNetWsClient/ChatClient.cs b/KfChatDotNetWsClient/ChatClient.cs index 91d3f6b..243159d 100644 --- a/KfChatDotNetWsClient/ChatClient.cs +++ b/KfChatDotNetWsClient/ChatClient.cs @@ -114,6 +114,12 @@ public class ChatClient _logger.Debug("Websocket client started!"); } + public void DisposeWsClient() + { + if (_wsClient == null) throw new WebSocketNotInitializedException(); + _wsClient.Dispose(); + } + public bool IsConnected() { return _wsClient is { IsRunning: true };