Skip to content

Commit

Permalink
Fix UDS connection exception handling and add test.
Browse files Browse the repository at this point in the history
  • Loading branch information
imcarolwang authored and mconnew committed Mar 5, 2024
1 parent 83e8abe commit 3f7b5d1
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -176,12 +176,48 @@ public void BasicIdentityOnlyAuthLinux()
}
}

[WcfFact]
[OuterLoop]
public void SocketExceptionHandlingTest()
{
string testString = new string('a', 3000);
IHost host = ServiceHelper.CreateWebHostBuilder<StartUpForUDS>(UDS.GetUDSFilePath());
using (host)
{
System.ServiceModel.ChannelFactory<IEchoService> 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<IEchoService>(binding,
new System.ServiceModel.EndpointAddress(uriBuilder.ToString()));
serviceProxy = factory.CreateChannel();
Assert.Throws<EndpointNotFoundException>(() => ((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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -854,12 +854,11 @@ public async ValueTask<IConnection> 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));
}

Expand Down

0 comments on commit 3f7b5d1

Please sign in to comment.