[Fix] Disconnecting socket client does not send close code (#2714)

* fix?

* whoops, debugging stuff
This commit is contained in:
Misha133
2023-08-10 16:19:10 +03:00
committed by GitHub
parent d5d7378e02
commit 6bb3777bf9
2 changed files with 19 additions and 9 deletions

View File

@@ -279,15 +279,17 @@ namespace Discord.API
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;
}

View File

@@ -110,9 +110,6 @@ namespace Discord.Net.WebSockets
{
_isDisconnecting = true;
try
{ _disconnectTokenSource.Cancel(false); }
catch { }
if (_client != null)
{
@@ -120,11 +117,22 @@ namespace Discord.Net.WebSockets
{
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;