mirror of
https://github.com/JKorf/CryptoExchange.Net.git
synced 2026-11-04 17:27:45 +00:00
Fixed cancellation source disposal race in CloseAsync (#300)
This commit is contained in:
@@ -446,27 +446,28 @@ 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)
|
|
||||||
{
|
{
|
||||||
|
if (!IsOpen)
|
||||||
_logger.SocketCloseAsyncSocketNotOpen(Id);
|
_logger.SocketCloseAsyncSocketNotOpen(Id);
|
||||||
return;
|
else
|
||||||
}
|
|
||||||
|
|
||||||
_logger.SocketClosing(Id);
|
_logger.SocketClosing(Id);
|
||||||
|
|
||||||
_closeTask = CloseInternalAsync();
|
_closeTask = CloseInternalAsync();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
_closeSem.Release();
|
_closeSem.Release();
|
||||||
}
|
}
|
||||||
|
|
||||||
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