From 01d9b32ee339152955f8b6fd1dd918136cdf0f28 Mon Sep 17 00:00:00 2001 From: Stephen Toub Date: Tue, 16 Jul 2019 07:07:22 -0400 Subject: [PATCH] Propagate abort exceptions from CreditManager.Dispose (dotnet/corefx#39520) 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/System/Net/Http/SocketsHttpHandler/CreditManager.cs | 9 ++++++--- .../src/System/Net/Http/SocketsHttpHandler/Http2Connection.cs | 4 ++-- .../src/System/Net/Http/SocketsHttpHandler/Http2Stream.cs | 2 +- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/CreditManager.cs b/src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/CreditManager.cs index 9363f95..b771c07 100644 --- a/src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/CreditManager.cs +++ b/src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/CreditManager.cs @@ -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)); } } } diff --git a/src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/Http2Connection.cs b/src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/Http2Connection.cs index b6d719d..b377bab 100644 --- a/src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/Http2Connection.cs +++ b/src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/Http2Connection.cs @@ -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() diff --git a/src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/Http2Stream.cs b/src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/Http2Stream.cs index ddb9dfa..6e33523 100644 --- a/src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/Http2Stream.cs +++ b/src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/Http2Stream.cs @@ -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 -- 2.7.4