fix: Connection deadlock when trying to Send and Disconnect (#1872)
This commit is contained in:
@@ -188,9 +188,9 @@ namespace Discord.API
|
|||||||
catch { }
|
catch { }
|
||||||
|
|
||||||
if (ex is GatewayReconnectException)
|
if (ex is GatewayReconnectException)
|
||||||
await WebSocketClient.DisconnectAsync(4000);
|
await WebSocketClient.DisconnectAsync(4000).ConfigureAwait(false);
|
||||||
else
|
else
|
||||||
await WebSocketClient.DisconnectAsync().ConfigureAwait(false);
|
await WebSocketClient.DisconnectAsync().ConfigureAwait(false);
|
||||||
|
|
||||||
ConnectionState = ConnectionState.Disconnected;
|
ConnectionState = ConnectionState.Disconnected;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -108,11 +108,11 @@ namespace Discord.Net.WebSockets
|
|||||||
}
|
}
|
||||||
private async Task DisconnectInternalAsync(int closeCode = 1000, bool isDisposing = false)
|
private async Task DisconnectInternalAsync(int closeCode = 1000, bool isDisposing = false)
|
||||||
{
|
{
|
||||||
|
_isDisconnecting = true;
|
||||||
|
|
||||||
try { _disconnectTokenSource.Cancel(false); }
|
try { _disconnectTokenSource.Cancel(false); }
|
||||||
catch { }
|
catch { }
|
||||||
|
|
||||||
_isDisconnecting = true;
|
|
||||||
|
|
||||||
if (_client != null)
|
if (_client != null)
|
||||||
{
|
{
|
||||||
if (!isDisposing)
|
if (!isDisposing)
|
||||||
@@ -166,7 +166,14 @@ namespace Discord.Net.WebSockets
|
|||||||
|
|
||||||
public async Task SendAsync(byte[] data, int index, int count, bool isText)
|
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
|
try
|
||||||
{
|
{
|
||||||
if (_client == null) return;
|
if (_client == null) return;
|
||||||
@@ -201,7 +208,7 @@ namespace Discord.Net.WebSockets
|
|||||||
{
|
{
|
||||||
while (!cancelToken.IsCancellationRequested)
|
while (!cancelToken.IsCancellationRequested)
|
||||||
{
|
{
|
||||||
WebSocketReceiveResult socketResult = await _client.ReceiveAsync(buffer, CancellationToken.None).ConfigureAwait(false);
|
WebSocketReceiveResult socketResult = await _client.ReceiveAsync(buffer, cancelToken).ConfigureAwait(false);
|
||||||
byte[] result;
|
byte[] result;
|
||||||
int resultCount;
|
int resultCount;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user