Skip to content

Commit

Permalink
In Dns.RunAsync calls AfterResolution when canceled (dotnet#104435)
Browse files Browse the repository at this point in the history
* Calling AfterResolution when canceled
* Mark log entry with OperationCanceledException
  • Loading branch information
rokonec authored Jul 10, 2024
1 parent f6d12a1 commit 5bf04bd
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/libraries/System.Net.NameResolution/src/System/Net/Dns.cs
Original file line number Diff line number Diff line change
Expand Up @@ -694,6 +694,8 @@ private static Task<TResult> RunAsync<TResult>(Func<object, long, TResult> func,
lock (s_tasks)
{
((ICollection<KeyValuePair<object, Task>>)s_tasks).Remove(new KeyValuePair<object, Task>(key!, task));
// Since it was canceled, func(..) had not executed and call AfterResolution it needs to be called here.
NameResolutionTelemetry.Log.AfterResolution(key!, startingTimestamp, new OperationCanceledException());
}
}, key, CancellationToken.None, TaskContinuationOptions.OnlyOnCanceled | TaskContinuationOptions.ExecuteSynchronously, TaskScheduler.Default);
}
Expand Down

0 comments on commit 5bf04bd

Please sign in to comment.