From facbdce3f7e075e8dc2e2a3eed1183ded333ec67 Mon Sep 17 00:00:00 2001 From: Alexander Nikolaev <55398552+alnikola@users.noreply.github.com> Date: Fri, 30 Jul 2021 14:21:00 +0200 Subject: [PATCH] Check _abortException before checking _shutdown flag (#56552) In case of an error aborting the connection, there is a race between a thread creating new `Http2Stream` to send a request and the thread looping in `ProcessIncomingFrames` that sets _shutdown flag and `_abortException`. If the request thread first sees `_shutdown == true`, then it won't see the `_abortException` even if it's set, so the request will be retried when it shouldn't. This PR adds `_abortException` check just before the `_shutdown == true` check to make sure an abort exception is observed. Fixes #1581 Fixes #56138 Fixes #56026 --- .../src/System/Net/Http/SocketsHttpHandler/Http2Connection.cs | 5 +++++ .../tests/FunctionalTests/HttpClientHandlerTest.Http2.cs | 1 - 2 files changed, 5 insertions(+), 1 deletion(-) 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 11d4d9c..ce524c4 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 @@ -1492,6 +1492,11 @@ namespace System.Net.Http Shutdown(); } + if (_abortException is not null) + { + throw GetRequestAbortedException(_abortException); + } + if (_shutdown) { // The connection has shut down. Throw a retryable exception so that this request will be handled on another connection. diff --git a/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTest.Http2.cs b/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTest.Http2.cs index 1aadb51..c9c5db6 100644 --- a/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTest.Http2.cs +++ b/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTest.Http2.cs @@ -243,7 +243,6 @@ namespace System.Net.Http.Functional.Tests } } - [ActiveIssue("https://github.com/dotnet/runtime/issues/1581")] [ConditionalTheory(nameof(SupportsAlpn))] [InlineData(SettingId.MaxFrameSize, 16383)] [InlineData(SettingId.MaxFrameSize, 162777216)] -- 2.7.4