diff --git a/src/System.Private.ServiceModel/tests/Scenarios/Binding/UDS/UDSBindingTests.cs b/src/System.Private.ServiceModel/tests/Scenarios/Binding/UDS/UDSBindingTests.cs index 9a62a6150ce..c6a68c6c713 100644 --- a/src/System.Private.ServiceModel/tests/Scenarios/Binding/UDS/UDSBindingTests.cs +++ b/src/System.Private.ServiceModel/tests/Scenarios/Binding/UDS/UDSBindingTests.cs @@ -176,12 +176,48 @@ public void BasicIdentityOnlyAuthLinux() } } + [WcfFact] + [OuterLoop] + public void SocketExceptionHandlingTest() + { + string testString = new string('a', 3000); + IHost host = ServiceHelper.CreateWebHostBuilder(UDS.GetUDSFilePath()); + using (host) + { + System.ServiceModel.ChannelFactory factory = null; + IEchoService serviceProxy = null; + host.Start(); + try + { + System.ServiceModel.UnixDomainSocketBinding binding = new UnixDomainSocketBinding(UnixDomainSocketSecurityMode.None); + var uriBuilder = new UriBuilder() + { + Scheme = "net.uds", + Path = UDS.GetInvalidUDSFilePath() + }; + factory = new System.ServiceModel.ChannelFactory(binding, + new System.ServiceModel.EndpointAddress(uriBuilder.ToString())); + serviceProxy = factory.CreateChannel(); + Assert.Throws(() => ((IChannel)serviceProxy).Open()); + } + finally + { + ServiceHelper.CloseServiceModelObjects((IChannel)serviceProxy, factory); + } + } + } + public class UDS { public static string GetUDSFilePath() { return Path.Combine(Path.GetTempPath(), "unix1.txt"); } + + public static string GetInvalidUDSFilePath() + { + return Path.Combine(Path.GetTempPath(), "invalid.txt"); + } } public class StartUpForUDS : UDS diff --git a/src/System.ServiceModel.UnixDomainSocket/src/System/ServiceModel/Channels/SocketConnection.cs b/src/System.ServiceModel.UnixDomainSocket/src/System/ServiceModel/Channels/SocketConnection.cs index 316ecfe0c9d..b53b452c308 100644 --- a/src/System.ServiceModel.UnixDomainSocket/src/System/ServiceModel/Channels/SocketConnection.cs +++ b/src/System.ServiceModel.UnixDomainSocket/src/System/ServiceModel/Channels/SocketConnection.cs @@ -854,12 +854,11 @@ public async ValueTask ConnectAsync(Uri uri, TimeSpan timeout) try { socketConnection = await CreateConnectionAsync(uri); - lastException = null; } catch (SocketException socketException) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError( - SocketConnectionInitiator.ConvertConnectException(lastException, uri, + SocketConnectionInitiator.ConvertConnectException(socketException, uri, timeoutHelper.ElapsedTime(), socketException)); }