Propagate abort exceptions from CreditManager.Dispose (dotnet/corefx#39520)
authorStephen Toub <stoub@microsoft.com>
Tue, 16 Jul 2019 11:07:22 +0000 (07:07 -0400)
committerGitHub <noreply@github.com>
Tue, 16 Jul 2019 11:07:22 +0000 (07:07 -0400)
Currently, if an abort occurs, it disposes of credit managers, and if there's a waiter on that credit manager, that waiter propagates an ObjectDisposedException.  It should instead propagate whatever exception resulted from the abort.

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

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

index 9363f95..b771c07 100644 (file)
@@ -4,12 +4,13 @@
 
 using System.Diagnostics;
 using System.Collections.Generic;
+using System.IO;
 using System.Threading;
 using System.Threading.Tasks;
 
 namespace System.Net.Http
 {
-    internal sealed class CreditManager : IDisposable
+    internal sealed class CreditManager
     {
         private readonly IHttpTrace _owner;
         private readonly string _name;
@@ -105,7 +106,7 @@ namespace System.Net.Http
             }
         }
 
-        public void Dispose()
+        public void Dispose(Exception abortException)
         {
             lock (SyncObject)
             {
@@ -120,7 +121,9 @@ namespace System.Net.Http
                 {
                     while (_waiters.TryDequeue(out Waiter waiter))
                     {
-                        waiter.TrySetException(CreateObjectDisposedException(forActiveWaiter: true));
+                        waiter.TrySetException(abortException != null ? (Exception)
+                            new IOException(SR.net_http_request_aborted, abortException) :
+                            CreateObjectDisposedException(forActiveWaiter: true));
                     }
                 }
             }
index b6d719d..b377bab 100644 (file)
@@ -1419,8 +1419,8 @@ namespace System.Net.Http
             // Do shutdown.
             _stream.Close();
 
-            _connectionWindow.Dispose();
-            _concurrentStreams.Dispose();
+            _connectionWindow.Dispose(_abortException);
+            _concurrentStreams.Dispose(_abortException);
         }
 
         public void Dispose()
index ddb9dfa..6e33523 100644 (file)
@@ -722,7 +722,7 @@ namespace System.Net.Http
                     {
                         _disposed = true;
 
-                        _streamWindow.Dispose();
+                        _streamWindow.Dispose(_abortException);
                         _responseBuffer.Dispose();
 
                         // TODO: ISSUE 31310: If the stream is not complete, we should send RST_STREAM