mirror of
https://github.com/barelyprofessional/KfChatDotNet.git
synced 2026-06-28 06:55:17 -04:00
Dispose and fully restart the WS client if it's choking due to TaskCanceledException
This commit is contained in:
@@ -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)
|
||||||
|
|||||||
@@ -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 };
|
||||||
|
|||||||
Reference in New Issue
Block a user