Properly map exceptions from NetworkStream ctor. (#39514)
authorMarie Píchová <11718369+ManickaP@users.noreply.github.com>
Mon, 20 Jul 2020 13:57:16 +0000 (15:57 +0200)
committerGitHub <noreply@github.com>
Mon, 20 Jul 2020 13:57:16 +0000 (15:57 +0200)
src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/ConnectHelper.cs

index 31b33df8c6b36df3babcbbc0112187ad0baa9664..48d530c2a03e544f523f496dbb0894f2914b07ad 100644 (file)
@@ -96,14 +96,14 @@ namespace System.Net.Http
                 {
                     socket.Connect(new DnsEndPoint(host, port));
                 }
+
+                return new NetworkStream(socket, ownsSocket: true);
             }
             catch (Exception e)
             {
                 socket.Dispose();
                 throw CreateWrappedException(e, host, port, cancellationToken);
             }
-
-            return new NetworkStream(socket, ownsSocket: true);
         }
 
         /// <summary>SocketAsyncEventArgs that carries with it additional state for a Task builder and a CancellationToken.</summary>