From a3e728a7b7b5ece523def0e6cf86567bb8faa6fc Mon Sep 17 00:00:00 2001 From: Ahmet Ibrahim Aksoy Date: Tue, 18 Jun 2024 08:14:15 +0200 Subject: [PATCH] [HTTP/3] Wrap Cancelled Request with OCE instead of QuicException (#103081) * Wrap Cancelled Request with OperationCanceledException instead of throwing QuicException as Inner * Handle wrapping OperationAborted in OCE on ReadResponseContent * Use properties from Concrete type * Convert OCE to TCE * Add comment for throwing TCE --- .../Net/Http/SocketsHttpHandler/Http3RequestStream.cs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/Http3RequestStream.cs b/src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/Http3RequestStream.cs index ef2532b2b22d0..d036e955c3047 100644 --- a/src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/Http3RequestStream.cs +++ b/src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/Http3RequestStream.cs @@ -275,6 +275,12 @@ await Task.WhenAny(sendRequestTask, readResponseTask).ConfigureAwait(false) == s Exception abortException = _connection.Abort(HttpProtocolException.CreateHttp3ConnectionException(code, SR.net_http_http3_connection_close)); throw new HttpRequestException(HttpRequestError.HttpProtocolError, SR.net_http_client_execution_error, abortException); } + catch (QuicException ex) when (ex.QuicError == QuicError.OperationAborted && cancellationToken.IsCancellationRequested) + { + // It is possible for QuicStream's code to throw an + // OperationAborted QuicException when cancellation is requested. + throw new TaskCanceledException(ex.Message, ex, cancellationToken); + } catch (QuicException ex) when (ex.QuicError == QuicError.OperationAborted && _connection.AbortException != null) { // we closed the connection already, propagate the AbortException @@ -1277,6 +1283,11 @@ private void HandleReadResponseContentException(Exception ex, CancellationToken : HttpRequestError.Unknown; throw new HttpRequestException(httpRequestError, SR.net_http_client_execution_error, _connection.AbortException); + case QuicException e when (e.QuicError == QuicError.OperationAborted && cancellationToken.IsCancellationRequested): + // It is possible for QuicStream's code to throw an + // OperationAborted QuicException when cancellation is requested. + throw new TaskCanceledException(e.Message, e, cancellationToken); + case HttpIOException: _connection.Abort(ex); ExceptionDispatchInfo.Throw(ex); // Rethrow.