Delete ClientWebSocket's event source (#38870)
authorStephen Toub <stoub@microsoft.com>
Wed, 8 Jul 2020 18:18:32 +0000 (14:18 -0400)
committerGitHub <noreply@github.com>
Wed, 8 Jul 2020 18:18:32 +0000 (14:18 -0400)
It's raising a single event for failed connects, and actual networking-related failures for failed connects will already be logged by the underlying API used.

By getting rid of the catch and rethrow, we can also avoid an extra layer of async state machine on connect.

src/libraries/System.Net.WebSockets.Client/src/System.Net.WebSockets.Client.csproj
src/libraries/System.Net.WebSockets.Client/src/System/Net/WebSockets/ClientWebSocket.cs
src/libraries/System.Net.WebSockets.Client/src/System/Net/WebSockets/NetEventSource.WebSockets.cs [deleted file]
src/libraries/System.Net.WebSockets.Client/tests/LoggingTest.cs [deleted file]
src/libraries/System.Net.WebSockets.Client/tests/System.Net.WebSockets.Client.Tests.csproj

index 61b1f5b..83b4c5a 100644 (file)
@@ -7,10 +7,8 @@
   <ItemGroup>
     <Compile Include="System\Net\WebSockets\ClientWebSocket.cs" />
     <Compile Include="System\Net\WebSockets\ClientWebSocketOptions.cs" Condition="'$(TargetsBrowser)' != 'true'" />
-    <Compile Include="System\Net\WebSockets\NetEventSource.WebSockets.cs" />
     <Compile Include="$(CommonPath)System\Net\UriScheme.cs" Link="Common\System\Net\UriScheme.cs" />
     <Compile Include="$(CommonPath)System\Net\WebSockets\WebSocketValidate.cs" Link="Common\System\Net\WebSockets\WebSocketValidate.cs" />
-    <Compile Include="$(CommonPath)System\Net\Logging\NetEventSource.Common.cs" Link="Common\System\Net\Logging\NetEventSource.Common.cs" />
   </ItemGroup>
   <ItemGroup Condition=" '$(TargetsBrowser)' != 'true'">
     <Compile Include="System\Net\WebSockets\WebSocketHandle.Managed.cs" />
index 6eb07cd..4d71e31 100644 (file)
@@ -82,24 +82,17 @@ namespace System.Net.WebSockets
             return ConnectAsyncCore(uri, cancellationToken);
         }
 
-        private async Task ConnectAsyncCore(Uri uri, CancellationToken cancellationToken)
+        private Task ConnectAsyncCore(Uri uri, CancellationToken cancellationToken)
         {
             _innerWebSocket = new WebSocketHandle();
-            try
-            {
-                // Change internal state to 'connected' to enable the other methods
-                if ((InternalState)Interlocked.CompareExchange(ref _state, (int)InternalState.Connected, (int)InternalState.Connecting) != InternalState.Connecting)
-                {
-                    throw new ObjectDisposedException(GetType().FullName); // Aborted/Disposed during connect.
-                }
 
-                await _innerWebSocket.ConnectAsync(uri, cancellationToken, Options).ConfigureAwait(false);
-            }
-            catch (Exception ex)
+            // Change internal state to 'connected' to enable the other methods
+            if ((InternalState)Interlocked.CompareExchange(ref _state, (int)InternalState.Connected, (int)InternalState.Connecting) != InternalState.Connecting)
             {
-                if (NetEventSource.IsEnabled) NetEventSource.Error(this, ex);
-                throw;
+                return Task.FromException(new ObjectDisposedException(nameof(ClientWebSocket))); // Aborted/Disposed during connect.
             }
+
+            return _innerWebSocket.ConnectAsync(uri, cancellationToken, Options);
         }
 
         public override Task SendAsync(ArraySegment<byte> buffer, WebSocketMessageType messageType, bool endOfMessage, CancellationToken cancellationToken) =>
diff --git a/src/libraries/System.Net.WebSockets.Client/src/System/Net/WebSockets/NetEventSource.WebSockets.cs b/src/libraries/System.Net.WebSockets.Client/src/System/Net/WebSockets/NetEventSource.WebSockets.cs
deleted file mode 100644 (file)
index 0195c37..0000000
+++ /dev/null
@@ -1,10 +0,0 @@
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-
-using System.Diagnostics.Tracing;
-
-namespace System.Net
-{
-    [EventSource(Name = "Microsoft-System-Net-WebSockets-Client")]
-    internal sealed partial class NetEventSource { }
-}
diff --git a/src/libraries/System.Net.WebSockets.Client/tests/LoggingTest.cs b/src/libraries/System.Net.WebSockets.Client/tests/LoggingTest.cs
deleted file mode 100644 (file)
index 3140ea4..0000000
+++ /dev/null
@@ -1,24 +0,0 @@
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-
-using System.Diagnostics.Tracing;
-using System.Reflection;
-using Xunit;
-
-namespace System.Net.WebSockets.Tests
-{
-    public class LoggingTest
-    {
-        [Fact]
-        public void EventSource_ExistsWithCorrectId()
-        {
-            Type esType = typeof(ClientWebSocket).GetTypeInfo().Assembly.GetType("System.Net.NetEventSource", throwOnError: true, ignoreCase: false);
-            Assert.NotNull(esType);
-
-            Assert.Equal("Microsoft-System-Net-WebSockets-Client", EventSource.GetName(esType));
-            Assert.Equal(Guid.Parse("71cddde3-cf58-52d5-094f-927828a09337"), EventSource.GetGuid(esType));
-
-            Assert.NotEmpty(EventSource.GenerateManifest(esType, "assemblyPathToIncludeInManifest"));
-        }
-    }
-}
index 4e5c5cb..413be9b 100644 (file)
@@ -38,7 +38,6 @@
     <Compile Include="ClientWebSocketUnitTest.cs" />
     <Compile Include="CloseTest.cs" />
     <Compile Include="ConnectTest.cs" />
-    <Compile Include="LoggingTest.cs" />
     <Compile Include="KeepAliveTest.cs" />
     <Compile Include="LoopbackHelper.cs" />
     <Compile Include="ResourceHelper.cs" />