From 760983410aa97c58635bf45affc0856e11e60998 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20K=C3=B6plinger?= Date: Tue, 24 Nov 2026 10:34:28 +0100 Subject: [PATCH] Preserve original failures in HTTP metrics and QUIC test diagnostics (#137472) Preserve original failures in networking tests uncovered while investigating #137416: - **HTTP metrics:** Enrichment runs from `finally`, including on failed requests where `Response` is legitimately null. Asserting inside the callback masks the original exception. Capture the response instead and assert `Same` after a successful send, keeping the original test flow. - **QUIC diagnostics:** `MsQuicRemoteExecutorTests` explicitly passes `null` as its output helper, so error-path logging can throw `NullReferenceException` and hide a connection failure. Make helper logging null-safe, but read `serverTask.Exception` independently so its fault remains observed even without logging. Test-only changes: no product, MsQuic version, retry, or timeout changes. The underlying TLS/QUIC flakes remain unresolved. **Validation:** The baseline build, 14 HTTP diagnostic-listener cases, and 6 focused QUIC cases passed on macOS ARM64 with locally built MsQuic 2.6.4/OpenSSL. Local cancellation and failed-handshake repros confirmed both masking bugs before the fixes; neither repro is in the final diff. Windows Schannel and full suites were not run. > [!NOTE] > Generated with GitHub Copilot. --------- Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- .../tests/FunctionalTests/MetricsTest.cs | 7 +++++-- .../tests/FunctionalTests/QuicTestBase.cs | 12 +++++++----- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/libraries/System.Net.Http/tests/FunctionalTests/MetricsTest.cs b/src/libraries/System.Net.Http/tests/FunctionalTests/MetricsTest.cs index 5768211d63d83a..4aaf4e34dfbdfb 100644 --- a/src/libraries/System.Net.Http/tests/FunctionalTests/MetricsTest.cs +++ b/src/libraries/System.Net.Http/tests/FunctionalTests/MetricsTest.cs @@ -550,15 +550,17 @@ await RemoteExecutor.Invoke(static async (testClassName, eventNameInner) => private async Task RequestDuration_CustomTags_DiagnosticListener_Recorded_Core(string eventName) { + HttpResponseMessage? enrichmentResponse = null; + FakeDiagnosticListenerObserver diagnosticListenerObserver = new(kv => { if (kv.Key == eventName) { HttpRequestMessage request = GetProperty(kv.Value, "Request"); - HttpMetricsEnrichmentContext.AddCallback(request, static ctx => + HttpMetricsEnrichmentContext.AddCallback(request, ctx => { ctx.AddCustomTag("observed?", "observed!"); - Assert.NotNull(ctx.Response); + enrichmentResponse = ctx.Response; }); } }); @@ -577,6 +579,7 @@ await LoopbackServerFactory.CreateClientAndServerAsync(async uri => }); using HttpResponseMessage response = await SendAsync(client, request); + Assert.Same(response, enrichmentResponse); Measurement m = Assert.Single(recorder.GetMeasurements()); VerifyRequestDuration(m, uri, UseVersion, 200); diff --git a/src/libraries/System.Net.Quic/tests/FunctionalTests/QuicTestBase.cs b/src/libraries/System.Net.Quic/tests/FunctionalTests/QuicTestBase.cs index d8e55cd4f00836..2b581c240d2f79 100644 --- a/src/libraries/System.Net.Quic/tests/FunctionalTests/QuicTestBase.cs +++ b/src/libraries/System.Net.Quic/tests/FunctionalTests/QuicTestBase.cs @@ -76,7 +76,7 @@ public bool RemoteCertificateValidationCallback(object sender, X509Certificate? public async Task AssertThrowsQuicExceptionAsync(QuicError expectedError, Func testCode) { QuicException ex = await Assert.ThrowsAsync(testCode); - _output.WriteLine(ex.ToString()); + _output?.WriteLine(ex.ToString()); Assert.Equal(expectedError, ex.QuicError); return ex; } @@ -224,7 +224,7 @@ internal ValueTask CreateQuicListener(IPEndPoint endpoint, Action< } catch (QuicException ex) when (ex.HResult == (int)SocketError.ConnectionRefused) { - _output.WriteLine($"ConnectAsync to {clientOptions.RemoteEndPoint} failed with {ex.Message}"); + _output?.WriteLine($"ConnectAsync to {clientOptions.RemoteEndPoint} failed with {ex.Message}"); await Task.Delay(delay); delay *= 2; @@ -252,7 +252,9 @@ internal ValueTask CreateQuicListener(IPEndPoint endpoint, Action< } if (serverTask.IsCompleted) { - _output.WriteLine($"Server {(serverTask.IsCompletedSuccessfully ? "succeeded" : "failed with " + serverTask.Exception)}"); + // Observe any server fault even when there is no output helper. + AggregateException? serverException = serverTask.Exception; + _output?.WriteLine($"Server {(serverTask.IsCompletedSuccessfully ? "succeeded" : "failed with " + serverException)}"); } throw; } @@ -325,7 +327,7 @@ await new[] } catch (ObjectDisposedException ex) { - _output.WriteLine(ex.ToString()); + _output?.WriteLine(ex.ToString()); } try { @@ -333,7 +335,7 @@ await new[] } catch (ObjectDisposedException ex) { - _output.WriteLine(ex.ToString()); + _output?.WriteLine(ex.ToString()); } } }