From 9ed32c81a6e3df1f8a73c69208ed6aac78b92067 Mon Sep 17 00:00:00 2001 From: Paulo Date: Tue, 15 Jun 2021 17:11:04 -0300 Subject: [PATCH] Bump to 2.4.1 and add deadlock changes --- Discord.Net.targets | 4 +-- src/Discord.Net.WebSocket/ConnectionManager.cs | 16 +---------- .../DiscordSocketApiClient.cs | 4 +-- .../Net/DefaultWebSocketClient.cs | 15 +++++++--- src/Discord.Net/Discord.Net.nuspec | 32 +++++++++++----------- 5 files changed, 32 insertions(+), 39 deletions(-) diff --git a/Discord.Net.targets b/Discord.Net.targets index d08d55535..7de539d20 100644 --- a/Discord.Net.targets +++ b/Discord.Net.targets @@ -1,7 +1,7 @@ - 2.4.0 - + 2.4.1 + dev latest Discord.Net Contributors discord;discordapp diff --git a/src/Discord.Net.WebSocket/ConnectionManager.cs b/src/Discord.Net.WebSocket/ConnectionManager.cs index 2237e2d1f..e444f359f 100644 --- a/src/Discord.Net.WebSocket/ConnectionManager.cs +++ b/src/Discord.Net.WebSocket/ConnectionManager.cs @@ -75,11 +75,6 @@ namespace Discord nextReconnectDelay = 1000; //Reset delay await _connectionPromise.Task.ConfigureAwait(false); } - catch (OperationCanceledException ex) - { - Cancel(); //In case this exception didn't come from another Error call - await DisconnectAsync(ex, !reconnectCancelToken.IsCancellationRequested).ConfigureAwait(false); - } catch (Exception ex) { Error(ex); //In case this exception didn't come from another Error call @@ -143,16 +138,7 @@ namespace Discord catch (OperationCanceledException) { } }); - try - { - await _onConnecting().ConfigureAwait(false); - } - catch (TaskCanceledException ex) - { - Exception innerEx = ex.InnerException ?? new OperationCanceledException("Failed to connect."); - Error(innerEx); - throw innerEx; - } + await _onConnecting().ConfigureAwait(false); await _logger.InfoAsync("Connected").ConfigureAwait(false); State = ConnectionState.Connected; diff --git a/src/Discord.Net.WebSocket/DiscordSocketApiClient.cs b/src/Discord.Net.WebSocket/DiscordSocketApiClient.cs index d14a314d6..5b4a6d904 100644 --- a/src/Discord.Net.WebSocket/DiscordSocketApiClient.cs +++ b/src/Discord.Net.WebSocket/DiscordSocketApiClient.cs @@ -189,9 +189,9 @@ namespace Discord.API catch { } if (ex is GatewayReconnectException) - await WebSocketClient.DisconnectAsync(4000); + await WebSocketClient.DisconnectAsync(4000).ConfigureAwait(false); else - await WebSocketClient.DisconnectAsync().ConfigureAwait(false); + await WebSocketClient.DisconnectAsync().ConfigureAwait(false); ConnectionState = ConnectionState.Disconnected; } diff --git a/src/Discord.Net.WebSocket/Net/DefaultWebSocketClient.cs b/src/Discord.Net.WebSocket/Net/DefaultWebSocketClient.cs index 4723ae57a..82e2f0573 100644 --- a/src/Discord.Net.WebSocket/Net/DefaultWebSocketClient.cs +++ b/src/Discord.Net.WebSocket/Net/DefaultWebSocketClient.cs @@ -108,11 +108,11 @@ namespace Discord.Net.WebSockets } private async Task DisconnectInternalAsync(int closeCode = 1000, bool isDisposing = false) { + _isDisconnecting = true; + try { _disconnectTokenSource.Cancel(false); } catch { } - _isDisconnecting = true; - if (_client != null) { if (!isDisposing) @@ -166,7 +166,14 @@ namespace Discord.Net.WebSockets public async Task SendAsync(byte[] data, int index, int count, bool isText) { - await _lock.WaitAsync().ConfigureAwait(false); + try + { + await _lock.WaitAsync(_cancelToken).ConfigureAwait(false); + } + catch (TaskCanceledException) + { + return; + } try { if (_client == null) return; @@ -201,7 +208,7 @@ namespace Discord.Net.WebSockets { while (!cancelToken.IsCancellationRequested) { - WebSocketReceiveResult socketResult = await _client.ReceiveAsync(buffer, CancellationToken.None).ConfigureAwait(false); + WebSocketReceiveResult socketResult = await _client.ReceiveAsync(buffer, cancelToken).ConfigureAwait(false); byte[] result; int resultCount; diff --git a/src/Discord.Net/Discord.Net.nuspec b/src/Discord.Net/Discord.Net.nuspec index b0fe17439..2ec5ecf49 100644 --- a/src/Discord.Net/Discord.Net.nuspec +++ b/src/Discord.Net/Discord.Net.nuspec @@ -2,7 +2,7 @@ Discord.Net - 2.4.0$suffix$ + 2.4.1-dev$suffix$ Discord.Net Discord.Net Contributors foxbot @@ -14,25 +14,25 @@ https://github.com/RogueException/Discord.Net/raw/dev/docs/marketing/logo/PackageLogo.png - - - - - + + + + + - - - - - + + + + + - - - - - + + + + +