1
0
Fork 0
mirror of https://github.com/VSadov/Satori.git synced 2025-06-09 17:44:48 +09:00

Fix cancelability of DNS queries (#104420)

* Fix cancelability of DNS queries
* Properly cascade cancelation info for connect by name exceptions
This commit is contained in:
Roman Konecny 2024-07-12 21:52:56 +03:00 committed by GitHub
parent 42b2fc819b
commit 45f3250677
Signed by: github
GPG key ID: B5690EEEBB952194
2 changed files with 9 additions and 3 deletions

View file

@ -97,7 +97,7 @@ namespace System.Net.Sockets
saea.RemoteEndPoint = remoteEP;
ValueTask connectTask = saea.ConnectAsync(this);
ValueTask connectTask = saea.ConnectAsync(this, saeaCancelable: cancellationToken.CanBeCanceled);
if (connectTask.IsCompleted || !cancellationToken.CanBeCanceled)
{
// Avoid async invocation overhead
@ -1210,11 +1210,11 @@ namespace System.Net.Sockets
ValueTask.FromException<int>(CreateException(error));
}
public ValueTask ConnectAsync(Socket socket)
public ValueTask ConnectAsync(Socket socket, bool saeaCancelable)
{
try
{
if (socket.ConnectAsync(this, userSocket: true, saeaCancelable: false))
if (socket.ConnectAsync(this, userSocket: true, saeaCancelable: saeaCancelable))
{
return new ValueTask(this, _mrvtsc.Version);
}

View file

@ -428,6 +428,12 @@ namespace System.Net.Sockets
{
_socketError = socketException.SocketErrorCode;
}
else if (exception is OperationCanceledException)
{
// Preserve information about the cancellation when it is canceled at non Socket operation.
// It is used to throw the right exception later in the stack.
_socketError = SocketError.OperationAborted;
}
else
{
_socketError = SocketError.SocketError;