mirror of
https://github.com/JKorf/CryptoExchange.Net.git
synced 2026-11-05 09:47:49 +00:00
Fixed cancellation source disposal race in CloseAsync (#300)
This commit is contained in:
@@ -446,18 +446,16 @@ namespace CryptoExchange.Net.Sockets.Default
|
|||||||
if (_closeTask?.IsCompleted == false)
|
if (_closeTask?.IsCompleted == false)
|
||||||
{
|
{
|
||||||
_logger.SocketCloseAsyncWaitingForExistingCloseTask(Id);
|
_logger.SocketCloseAsyncWaitingForExistingCloseTask(Id);
|
||||||
await _closeTask.ConfigureAwait(false);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
else
|
||||||
if (!IsOpen)
|
|
||||||
{
|
{
|
||||||
_logger.SocketCloseAsyncSocketNotOpen(Id);
|
if (!IsOpen)
|
||||||
return;
|
_logger.SocketCloseAsyncSocketNotOpen(Id);
|
||||||
}
|
else
|
||||||
|
_logger.SocketClosing(Id);
|
||||||
|
|
||||||
_logger.SocketClosing(Id);
|
_closeTask = CloseInternalAsync();
|
||||||
_closeTask = CloseInternalAsync();
|
}
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
@@ -465,8 +463,11 @@ namespace CryptoExchange.Net.Sockets.Default
|
|||||||
}
|
}
|
||||||
|
|
||||||
await _closeTask.ConfigureAwait(false);
|
await _closeTask.ConfigureAwait(false);
|
||||||
|
|
||||||
|
// Processing may still be running after the socket closes; finish before the caller disposes it.
|
||||||
if(_processTask != null)
|
if(_processTask != null)
|
||||||
await _processTask.ConfigureAwait(false);
|
await _processTask.ConfigureAwait(false);
|
||||||
|
|
||||||
await (OnClose?.Invoke() ?? Task.CompletedTask).ConfigureAwait(false);
|
await (OnClose?.Invoke() ?? Task.CompletedTask).ConfigureAwait(false);
|
||||||
_logger.SocketClosed(Id);
|
_logger.SocketClosed(Id);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user