fix: Connection deadlock when trying to Send and Disconnect (#1872)
This commit is contained in:
@@ -188,7 +188,7 @@ namespace Discord.API
|
||||
catch { }
|
||||
|
||||
if (ex is GatewayReconnectException)
|
||||
await WebSocketClient.DisconnectAsync(4000);
|
||||
await WebSocketClient.DisconnectAsync(4000).ConfigureAwait(false);
|
||||
else
|
||||
await WebSocketClient.DisconnectAsync().ConfigureAwait(false);
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user