diff --git a/src/libraries/Common/src/System/Net/Logging/NetEventSource.Common.Associate.cs b/src/libraries/Common/src/System/Net/Logging/NetEventSource.Common.Associate.cs index 82d9e70f6eb5b0..6104c8f9f5a127 100644 --- a/src/libraries/Common/src/System/Net/Logging/NetEventSource.Common.Associate.cs +++ b/src/libraries/Common/src/System/Net/Logging/NetEventSource.Common.Associate.cs @@ -32,7 +32,7 @@ public static void Associate(object? thisOrContextObject, object first, object s [Event(AssociateEventId, Level = EventLevel.Informational, Keywords = Keywords.Default, Message = "[{2}]<-->[{3}]")] private void Associate(string thisOrContextObject, string? memberName, string first, string second) { - Debug.Assert(IsEnabled()); + //Debug.Assert(IsEnabled()); WriteEvent(AssociateEventId, thisOrContextObject, memberName ?? MissingMember, first, second); } diff --git a/src/libraries/Common/src/System/Net/Logging/NetEventSource.Common.cs b/src/libraries/Common/src/System/Net/Logging/NetEventSource.Common.cs index 8dadcacb9be91f..a0ed7d0052a841 100644 --- a/src/libraries/Common/src/System/Net/Logging/NetEventSource.Common.cs +++ b/src/libraries/Common/src/System/Net/Logging/NetEventSource.Common.cs @@ -77,7 +77,7 @@ public static void Info(object? thisOrContextObject, object? message, [CallerMem [Event(InfoEventId, Level = EventLevel.Informational, Keywords = Keywords.Default)] private void Info(string thisOrContextObject, string? memberName, string? message) { - Debug.Assert(IsEnabled()); + //Debug.Assert(IsEnabled()); WriteEvent(InfoEventId, thisOrContextObject, memberName ?? MissingMember, message); } #endregion @@ -102,7 +102,7 @@ public static void Error(object? thisOrContextObject, object message, [CallerMem [Event(ErrorEventId, Level = EventLevel.Error, Keywords = Keywords.Default)] private void ErrorMessage(string thisOrContextObject, string? memberName, string? message) { - Debug.Assert(IsEnabled()); + //Debug.Assert(IsEnabled()); WriteEvent(ErrorEventId, thisOrContextObject, memberName ?? MissingMember, message); } #endregion diff --git a/src/libraries/System.Net.Http/tests/FunctionalTests/DiagnosticsTests.cs b/src/libraries/System.Net.Http/tests/FunctionalTests/DiagnosticsTests.cs index 9059a05d49f6bf..af1b3cedb6fc6e 100644 --- a/src/libraries/System.Net.Http/tests/FunctionalTests/DiagnosticsTests.cs +++ b/src/libraries/System.Net.Http/tests/FunctionalTests/DiagnosticsTests.cs @@ -18,6 +18,7 @@ namespace System.Net.Http.Functional.Tests { + [ActiveIssue("Foo")] public abstract class DiagnosticsTest : HttpClientHandlerTestBase { private const string EnableActivityPropagationEnvironmentVariableSettingName = "DOTNET_SYSTEM_NET_HTTP_ENABLEACTIVITYPROPAGATION"; diff --git a/src/libraries/System.Net.Http/tests/FunctionalTests/SocketsHttpHandlerTest.Cancellation.cs b/src/libraries/System.Net.Http/tests/FunctionalTests/SocketsHttpHandlerTest.Cancellation.cs index ae1669c18e68b8..4d983302d8791b 100644 --- a/src/libraries/System.Net.Http/tests/FunctionalTests/SocketsHttpHandlerTest.Cancellation.cs +++ b/src/libraries/System.Net.Http/tests/FunctionalTests/SocketsHttpHandlerTest.Cancellation.cs @@ -10,6 +10,7 @@ using Microsoft.DotNet.RemoteExecutor; using Xunit; using Xunit.Abstractions; +using TestUtilities; namespace System.Net.Http.Functional.Tests { @@ -18,6 +19,11 @@ public abstract class SocketsHttpHandler_Cancellation_Test : HttpClientHandler_C { protected SocketsHttpHandler_Cancellation_Test(ITestOutputHelper output) : base(output) { } + [Fact] public async Task ValidateConnectTimeout2() => await ConnectionFailure_AfterInitialRequestCancelled_SecondRequestSucceedsOnNewConnection(true); + [Fact] public async Task ValidateConnectTimeout3() => await ConnectionFailure_AfterInitialRequestCancelled_SecondRequestSucceedsOnNewConnection(true); + [Fact][OuterLoop] public async Task ValidateConnectTimeout4() => await ConnectionFailure_AfterInitialRequestCancelled_SecondRequestSucceedsOnNewConnection(true); + [Fact][OuterLoop] public async Task ValidateConnectTimeout5() => await ConnectionFailure_AfterInitialRequestCancelled_SecondRequestSucceedsOnNewConnection(true); + private async Task ValidateConnectTimeout(HttpMessageInvoker invoker, Uri uri, int minElapsed, int maxElapsed) { var sw = Stopwatch.StartNew(); @@ -81,6 +87,11 @@ await LoopbackServerFactory.CreateClientAndServerAsync(async uri => options: new GenericLoopbackOptions() { UseSsl = useSsl }); } + [Fact] public async Task ConnectTimeout_PlaintextStreamFilterTimesOut_Throws2() => await ConnectionFailure_AfterInitialRequestCancelled_SecondRequestSucceedsOnNewConnection(true); + [Fact] public async Task ConnectTimeout_PlaintextStreamFilterTimesOut_Throws3() => await ConnectionFailure_AfterInitialRequestCancelled_SecondRequestSucceedsOnNewConnection(true); + [Fact][OuterLoop] public async Task ConnectTimeout_PlaintextStreamFilterTimesOut_Throws4() => await ConnectionFailure_AfterInitialRequestCancelled_SecondRequestSucceedsOnNewConnection(true); + [Fact][OuterLoop] public async Task ConnectTimeout_PlaintextStreamFilterTimesOut_Throws5() => await ConnectionFailure_AfterInitialRequestCancelled_SecondRequestSucceedsOnNewConnection(true); + [OuterLoop] [Fact] public async Task ConnectTimeout_PlaintextStreamFilterTimesOut_Throws() @@ -107,36 +118,35 @@ await LoopbackServerFactory.CreateClientAndServerAsync(async uri => options: new GenericLoopbackOptions() { UseSsl = false }); } - [OuterLoop] + [Fact] public async Task ConnectionFailure_AfterInitialRequestCancelled_SecondRequestSucceedsOnNewConnection2() => await ConnectionFailure_AfterInitialRequestCancelled_SecondRequestSucceedsOnNewConnection(true); + [Fact] public async Task ConnectionFailure_AfterInitialRequestCancelled_SecondRequestSucceedsOnNewConnection3() => await ConnectionFailure_AfterInitialRequestCancelled_SecondRequestSucceedsOnNewConnection(true); + + [Fact][OuterLoop] public async Task ConnectionFailure_AfterInitialRequestCancelled_SecondRequestSucceedsOnNewConnection4() => await ConnectionFailure_AfterInitialRequestCancelled_SecondRequestSucceedsOnNewConnection(true); + [Fact][OuterLoop] public async Task ConnectionFailure_AfterInitialRequestCancelled_SecondRequestSucceedsOnNewConnection5() => await ConnectionFailure_AfterInitialRequestCancelled_SecondRequestSucceedsOnNewConnection(true); + [Theory] [InlineData(true)] [InlineData(false)] public async Task ConnectionFailure_AfterInitialRequestCancelled_SecondRequestSucceedsOnNewConnection(bool useSsl) { - if (UseVersion == HttpVersion.Version30) + if (UseVersion.Major != 1 || !TestAsync || !useSsl) { - // HTTP3 does not support ConnectCallback return; } - if (!TestAsync) - { - // Test relies on ordering of async operations, so we can't test the sync case - return; - } + using var listener = new TestEventListener(_output, TestEventListener.NetworkingEvents); await LoopbackServerFactory.CreateClientAndServerAsync(async uri => { int connectCount = 0; - TaskCompletionSource tcsFirstConnectionInitiated = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); - TaskCompletionSource tcsFirstRequestCanceled = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var tcsFirstConnectionInitiated = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var tcsFirstRequestCanceled = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); - using (var handler = CreateHttpClientHandler(allowAllCertificates: true)) - using (var client = CreateHttpClient(handler)) + using (HttpClientHandler handler = CreateHttpClientHandler()) + using (HttpClient client = CreateHttpClient(handler)) { - var socketsHandler = GetUnderlyingSocketsHttpHandler(handler); - socketsHandler.ConnectCallback = async (context, token) => + GetUnderlyingSocketsHttpHandler(handler).ConnectCallback = async (context, token) => { // Note we force serialization of connection creation by waiting on tcsFirstConnectionInitiated below, // so we don't need to worry about concurrent access to connectCount. @@ -145,6 +155,8 @@ await LoopbackServerFactory.CreateClientAndServerAsync(async uri => Assert.True(connectCount <= 2); + _output.WriteLine($"Connection count {connectCount}"); + if (isFirstConnection) { tcsFirstConnectionInitiated.SetResult(); @@ -157,6 +169,8 @@ await LoopbackServerFactory.CreateClientAndServerAsync(async uri => // Wait until first request is cancelled and has completed await tcsFirstRequestCanceled.Task; + _output.WriteLine($"After tcsFirstRequestCanceled {isFirstConnection}"); + if (isFirstConnection) { // Fail the first connection attempt @@ -170,27 +184,34 @@ await LoopbackServerFactory.CreateClientAndServerAsync(async uri => }; using CancellationTokenSource cts = new CancellationTokenSource(); - Task t1 = client.SendAsync(new HttpRequestMessage(HttpMethod.Get, uri) { Version = UseVersion, VersionPolicy = HttpVersionPolicy.RequestVersionExact }, cts.Token); + Task t1 = client.SendAsync(CreateRequest(HttpMethod.Get, uri, UseVersion, exactVersion: true), cts.Token); + _output.WriteLine("t1"); // Wait for the connection attempt to be initiated before we send the second request, to avoid races in connection creation await tcsFirstConnectionInitiated.Task; - Task t2 = client.SendAsync(new HttpRequestMessage(HttpMethod.Get, uri) { Version = UseVersion, VersionPolicy = HttpVersionPolicy.RequestVersionExact }, default); + Task t2 = client.SendAsync(CreateRequest(HttpMethod.Get, uri, UseVersion, exactVersion: true), CancellationToken.None); + _output.WriteLine("t2"); // Cancel the first message and wait for it to complete cts.Cancel(); await Assert.ThrowsAnyAsync(() => t1); + _output.WriteLine("ThrowsAnyAsync"); // Signal connections to proceed tcsFirstRequestCanceled.SetResult(); // Second request should succeed, even though the first connection failed HttpResponseMessage resp2 = await t2; + _output.WriteLine("resp2"); Assert.Equal(HttpStatusCode.OK, resp2.StatusCode); Assert.Equal("Hello world", await resp2.Content.ReadAsStringAsync()); + + Assert.True(connectCount == 2); } }, async server => { - await server.AcceptConnectionSendResponseAndCloseAsync(content: "Hello world"); + await server.HandleRequestAsync(content: "Hello world"); + _output.WriteLine("Server done"); }, options: new GenericLoopbackOptions() { UseSsl = useSsl }); } @@ -393,6 +414,11 @@ await RemoteExecutor.Invoke(static async (versionString, timoutStr) => }, UseVersion.ToString(), timeout.ToString()).DisposeAsync(); } + [Fact] public async Task PendingConnectionTimeout_HighValue_PendingConnectionIsNotCancelled2() => await ConnectionFailure_AfterInitialRequestCancelled_SecondRequestSucceedsOnNewConnection(true); + [Fact] public async Task PendingConnectionTimeout_HighValue_PendingConnectionIsNotCancelled3() => await ConnectionFailure_AfterInitialRequestCancelled_SecondRequestSucceedsOnNewConnection(true); + [Fact] [OuterLoop] public async Task PendingConnectionTimeout_HighValue_PendingConnectionIsNotCancelled4() => await ConnectionFailure_AfterInitialRequestCancelled_SecondRequestSucceedsOnNewConnection(true); + [Fact] [OuterLoop] public async Task PendingConnectionTimeout_HighValue_PendingConnectionIsNotCancelled5() => await ConnectionFailure_AfterInitialRequestCancelled_SecondRequestSucceedsOnNewConnection(true); + private sealed class SetTcsContent : StreamContent { private readonly TaskCompletionSource _tcs; diff --git a/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/NetEventSource.NetworkInformation.cs b/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/NetEventSource.NetworkInformation.cs index 87a07eb1cdd2a0..efd83d8b6e531d 100644 --- a/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/NetEventSource.NetworkInformation.cs +++ b/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/NetEventSource.NetworkInformation.cs @@ -21,7 +21,7 @@ public static void Error(Exception exception, [CallerMemberName] string? memberN [Event(ErrorEventId, Level = EventLevel.Error)] private void ErrorMessage(string memberName, string message) { - Debug.Assert(IsEnabled()); + //Debug.Assert(IsEnabled()); WriteEvent(ErrorEventId, memberName, message); } }