Propagate correct exception in Http2Connection.Abort (dotnet/corefx#39496)
authorStephen Toub <stoub@microsoft.com>
Mon, 15 Jul 2019 21:17:18 +0000 (17:17 -0400)
committerGitHub <noreply@github.com>
Mon, 15 Jul 2019 21:17:18 +0000 (17:17 -0400)
Ensure we pass the `_abortException`, not `abortException`, to the streams, and log any non-duplicate exception.

Commit migrated from https://github.com/dotnet/corefx/commit/cfccc26f9e77fa9f745857ec48a256309e29f39d

src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/Http2Connection.cs

index 6ea5cd0..b6d719d 100644 (file)
@@ -1277,8 +1277,15 @@ namespace System.Net.Http
         private void Abort(Exception abortException)
         {
             // The connection has failed, e.g. failed IO or a connection-level frame error.
-            Interlocked.CompareExchange(ref _abortException, abortException, null);
-            AbortStreams(abortException);
+            if (Interlocked.CompareExchange(ref _abortException, abortException, null) != null &&
+                NetEventSource.IsEnabled &&
+                !ReferenceEquals(_abortException, abortException))
+            {
+                // Lost the race to set the field to another exception, so just trace this one.
+                Trace($"{nameof(abortException)}=={abortException}");
+            }
+
+            AbortStreams(_abortException);
         }
 
         /// <summary>Gets whether the connection exceeded any of the connection limits.</summary>