From 30196bd43f17916eee59bb8229bdd9864e20d61c Mon Sep 17 00:00:00 2001 From: RogueException Date: Sat, 30 Jan 2016 12:23:47 -0400 Subject: [PATCH] Ignore errors during AudioClient cleanup --- src/Discord.Net.Audio/Net/VoiceSocket.cs | 19 +++++++++++++++---- src/Discord.Net/DiscordClient.cs | 1 - 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/Discord.Net.Audio/Net/VoiceSocket.cs b/src/Discord.Net.Audio/Net/VoiceSocket.cs index 1a1d72284..43ef6c45f 100644 --- a/src/Discord.Net.Audio/Net/VoiceSocket.cs +++ b/src/Discord.Net.Audio/Net/VoiceSocket.cs @@ -129,11 +129,19 @@ namespace Discord.Net.WebSockets protected override async Task Cleanup() { var sendThread = _sendTask; - if (sendThread != null) await sendThread.ConfigureAwait(false); + if (sendThread != null) + { + try { await sendThread.ConfigureAwait(false); } + catch (Exception) { } //Ignore any errors during cleanup + } _sendTask = null; var receiveThread = _receiveTask; - if (receiveThread != null) await receiveThread.ConfigureAwait(false); + if (receiveThread != null) + { + try { await receiveThread.ConfigureAwait(false); } + catch (Exception) { } //Ignore any errors during cleanup + } _receiveTask = null; OpusDecoder decoder; @@ -384,8 +392,11 @@ namespace Discord.Net.WebSockets } #if !DOTNET5_4 //Closes the UDP socket when _disconnectToken is triggered, since UDPClient doesn't allow passing a canceltoken - private Task WatcherAsync() - => CancelToken.Wait().ContinueWith(_ => _udp.Close()); + private async Task WatcherAsync() + { + await CancelToken.Wait(); + _udp.Close(); + } #endif protected override async Task ProcessMessage(string json) diff --git a/src/Discord.Net/DiscordClient.cs b/src/Discord.Net/DiscordClient.cs index b75ac5872..f05f94983 100644 --- a/src/Discord.Net/DiscordClient.cs +++ b/src/Discord.Net/DiscordClient.cs @@ -278,7 +278,6 @@ namespace Discord if (Config.UseMessageQueue) MessageQueue.Clear(); - await GatewaySocket.Disconnect().ConfigureAwait(false); ClientAPI.Token = null;