diff --git a/src/Discord.Net.WebSocket/DiscordSocketApiClient.cs b/src/Discord.Net.WebSocket/DiscordSocketApiClient.cs index 75960b173e..ab12ab7b0c 100644 --- a/src/Discord.Net.WebSocket/DiscordSocketApiClient.cs +++ b/src/Discord.Net.WebSocket/DiscordSocketApiClient.cs @@ -279,15 +279,17 @@ internal override async Task DisconnectInternalAsync(Exception ex = null) return; ConnectionState = ConnectionState.Disconnecting; - try - { _connectCancelToken?.Cancel(false); } - catch { } - if (ex is GatewayReconnectException) await WebSocketClient.DisconnectAsync(4000).ConfigureAwait(false); else await WebSocketClient.DisconnectAsync().ConfigureAwait(false); + try + { + _connectCancelToken?.Cancel(false); + } + catch { } + ConnectionState = ConnectionState.Disconnected; } diff --git a/src/Discord.Net.WebSocket/Net/DefaultWebSocketClient.cs b/src/Discord.Net.WebSocket/Net/DefaultWebSocketClient.cs index c4d354cb0c..bcdbf9036c 100644 --- a/src/Discord.Net.WebSocket/Net/DefaultWebSocketClient.cs +++ b/src/Discord.Net.WebSocket/Net/DefaultWebSocketClient.cs @@ -110,9 +110,6 @@ private async Task DisconnectInternalAsync(int closeCode = 1000, bool isDisposin { _isDisconnecting = true; - try - { _disconnectTokenSource.Cancel(false); } - catch { } if (_client != null) { @@ -120,11 +117,22 @@ private async Task DisconnectInternalAsync(int closeCode = 1000, bool isDisposin { var status = (WebSocketCloseStatus)closeCode; try - { await _client.CloseOutputAsync(status, "", new CancellationToken()); } + { + await _client.CloseOutputAsync(status, "", new CancellationToken()); + } catch { } } + try - { _client.Dispose(); } + { + _client.Dispose(); + } + catch { } + + try + { + _disconnectTokenSource.Cancel(false); + } catch { } _client = null;