Don't activate the canceltoken in websockets before the disconnectreason has been set.
This commit is contained in:
@@ -42,7 +42,7 @@ namespace Discord
|
|||||||
}
|
}
|
||||||
catch (OperationCanceledException)
|
catch (OperationCanceledException)
|
||||||
{
|
{
|
||||||
throw _disconnectReason;
|
throw _disconnectReason;// ?? new Exception("Operation was cancelled");
|
||||||
}
|
}
|
||||||
try { _connectWaitOnLogin2.Wait(cancelToken); } //Waiting on READY handler
|
try { _connectWaitOnLogin2.Wait(cancelToken); } //Waiting on READY handler
|
||||||
catch (OperationCanceledException) { return; }
|
catch (OperationCanceledException) { return; }
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ namespace Discord
|
|||||||
protected override void OnConnect()
|
protected override void OnConnect()
|
||||||
{
|
{
|
||||||
_udp = new UdpClient(new IPEndPoint(IPAddress.Any, 0));
|
_udp = new UdpClient(new IPEndPoint(IPAddress.Any, 0));
|
||||||
#if !DNX451
|
#if !DNX451 && !MONO
|
||||||
_udp.AllowNatTraversal(true);
|
_udp.AllowNatTraversal(true);
|
||||||
#endif
|
#endif
|
||||||
_isReady = false;
|
_isReady = false;
|
||||||
@@ -132,7 +132,6 @@ namespace Discord
|
|||||||
catch (OperationCanceledException) { }
|
catch (OperationCanceledException) { }
|
||||||
catch (ObjectDisposedException) { }
|
catch (ObjectDisposedException) { }
|
||||||
catch (Exception ex) { DisconnectInternal(ex); }
|
catch (Exception ex) { DisconnectInternal(ex); }
|
||||||
finally { DisconnectInternal(); }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#if USE_THREAD
|
#if USE_THREAD
|
||||||
@@ -213,7 +212,6 @@ namespace Discord
|
|||||||
catch (OperationCanceledException) { }
|
catch (OperationCanceledException) { }
|
||||||
catch (ObjectDisposedException) { }
|
catch (ObjectDisposedException) { }
|
||||||
catch (Exception ex) { DisconnectInternal(ex); }
|
catch (Exception ex) { DisconnectInternal(ex); }
|
||||||
finally { DisconnectInternal(); }
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
//Closes the UDP socket when _disconnectToken is triggered, since UDPClient doesn't allow passing a canceltoken
|
//Closes the UDP socket when _disconnectToken is triggered, since UDPClient doesn't allow passing a canceltoken
|
||||||
|
|||||||
@@ -97,11 +97,7 @@ namespace Discord
|
|||||||
try { await _task; } catch (NullReferenceException) { }
|
try { await _task; } catch (NullReferenceException) { }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void DisconnectInternal()
|
|
||||||
{
|
|
||||||
_disconnectToken.Cancel();
|
|
||||||
}
|
|
||||||
protected void DisconnectInternal(Exception ex, bool isUnexpected = true)
|
protected void DisconnectInternal(Exception ex, bool isUnexpected = true)
|
||||||
{
|
{
|
||||||
if (_disconnectReason == null)
|
if (_disconnectReason == null)
|
||||||
@@ -186,7 +182,6 @@ namespace Discord
|
|||||||
}
|
}
|
||||||
catch (OperationCanceledException) { }
|
catch (OperationCanceledException) { }
|
||||||
catch (Exception ex) { DisconnectInternal(ex); }
|
catch (Exception ex) { DisconnectInternal(ex); }
|
||||||
finally { DisconnectInternal(); }
|
|
||||||
}
|
}
|
||||||
private async Task SendAsync()
|
private async Task SendAsync()
|
||||||
{
|
{
|
||||||
@@ -215,7 +210,6 @@ namespace Discord
|
|||||||
}
|
}
|
||||||
catch (OperationCanceledException) { }
|
catch (OperationCanceledException) { }
|
||||||
catch (Exception ex) { DisconnectInternal(ex); }
|
catch (Exception ex) { DisconnectInternal(ex); }
|
||||||
finally { DisconnectInternal(); }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract Task ProcessMessage(string json);
|
protected abstract Task ProcessMessage(string json);
|
||||||
|
|||||||
Reference in New Issue
Block a user