diff --git a/src/Discord.Net/DiscordDataSocket.cs b/src/Discord.Net/DiscordDataSocket.cs index d2d40604e..bced9a8a2 100644 --- a/src/Discord.Net/DiscordDataSocket.cs +++ b/src/Discord.Net/DiscordDataSocket.cs @@ -42,7 +42,10 @@ namespace Discord } catch (OperationCanceledException) { - _disconnectReason.Throw(); + if (_disconnectReason == null) + throw new Exception("An unknown websocket error occurred."); + else + _disconnectReason.Throw(); } try { _connectWaitOnLogin2.Wait(cancelToken); } //Waiting on READY handler catch (OperationCanceledException) { return; } diff --git a/src/Discord.Net/DiscordVoiceSocket.cs b/src/Discord.Net/DiscordVoiceSocket.cs index 37892316f..91b37e939 100644 --- a/src/Discord.Net/DiscordVoiceSocket.cs +++ b/src/Discord.Net/DiscordVoiceSocket.cs @@ -109,7 +109,10 @@ namespace Discord } catch (OperationCanceledException) { - _disconnectReason.Throw(); + if (_disconnectReason == null) + throw new Exception("An unknown websocket error occurred."); + else + _disconnectReason.Throw(); } SetConnected(); diff --git a/src/Discord.Net/DiscordWebSocket.cs b/src/Discord.Net/DiscordWebSocket.cs index 4ca1bb6f8..3a8f28a29 100644 --- a/src/Discord.Net/DiscordWebSocket.cs +++ b/src/Discord.Net/DiscordWebSocket.cs @@ -45,6 +45,7 @@ namespace Discord await DisconnectAsync(); _disconnectToken = new CancellationTokenSource(); + _disconnectReason = null; var cancelToken = _disconnectToken.Token; _webSocket = new ClientWebSocket(); @@ -78,8 +79,7 @@ namespace Discord _webSocket = null; byte[] ignored; while (_sendQueue.TryDequeue(out ignored)) { } - - _disconnectReason = null; + _task = null; if (_isConnected) {