Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] NullReferenceException in SocketConnectionInitiator for UnixDomainSocket when cannot connect to server instead of meaningful error #5433

Open
DenisDoroshko opened this issue Feb 27, 2024 · 1 comment
Assignees
Labels

Comments

@DenisDoroshko
Copy link

DenisDoroshko commented Feb 27, 2024

Describe the bug
In SocketConnectionInitiator when cannot connect to server SocketException occurs, but due to incorrect handling instead of processing that exception NullReferenceException is thrown which is confusing

lastException is null if there is any exception in CreateConnectionAsync:
image

So further in ConvertConnectException we shouldn't check for lastException or check if it's not null and check innerException instead:
image

To Reproduce
Steps to reproduce the behavior:

  1. Run projects in attached solution(server and client)
    ExceptionSample.zip
  2. Press enter in client project to start call
  3. See NullReferenceException when using invalid path instead of more meaningful error
Unhandled exception. System.NullReferenceException: Object reference not set to an instance of an object.
   at System.ServiceModel.Channels.SocketConnectionInitiator.ConvertConnectException(SocketException socketException, Uri remoteUri, TimeSpan timeSpent, Exception innerException)
   at System.ServiceModel.Channels.SocketConnectionInitiator.ConnectAsync(Uri uri, TimeSpan timeout)
   at System.ServiceModel.Channels.BufferedConnectionInitiator.ConnectAsync(Uri uri, TimeSpan timeout)
   at System.ServiceModel.Channels.ConnectionPoolHelper.EstablishConnectionAsync(TimeSpan timeout)
   at System.ServiceModel.Channels.ClientFramingDuplexSessionChannel.OnOpenAsync(TimeSpan timeout)
   at System.ServiceModel.Channels.CommunicationObject.OnOpenAsyncInternal(TimeSpan timeout)
   at System.ServiceModel.Channels.CommunicationObject.System.ServiceModel.IAsyncCommunicationObject.OpenAsync(TimeSpan timeout)
   at System.ServiceModel.Channels.ServiceChannel.OnOpenAsync(TimeSpan timeout)
   at System.ServiceModel.Channels.CommunicationObject.OnOpenAsyncInternal(TimeSpan timeout)
   at System.ServiceModel.Channels.CommunicationObject.System.ServiceModel.IAsyncCommunicationObject.OpenAsync(TimeSpan timeout)
   at System.Runtime.TaskHelpers.WaitForCompletion(Task task)
   at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
   at System.ServiceModel.Channels.CommunicationObject.Open()
   at System.ServiceModel.Channels.ServiceChannelProxy.System.ServiceModel.ICommunicationObject.Open()
   at Program.<Main>$(String[] args) in C:\Users\user\Desktop\ExceptionSample\ExceptionSample\Program.cs:line 15

Video demo:
https://github.com/dotnet/wcf/assets/71182505/cf649b99-29c1-4804-b9ef-5b426e952a9f

Expected behavior
NullReferenceException shouldn't happen and SocketException should be processed in some way.

Screenshots
If applicable, add screenshots to help explain your problem.
Exception in https://github.com/dotnet/wcf/blob/main/src/System.ServiceModel.UnixDomainSocket/src/System/ServiceModel/Channels/SocketConnection.cs#L792
image

Additional context
Add any other context about the problem here.

@DenisDoroshko DenisDoroshko changed the title [Bug] NullReferenceException in SocketConnectionInitiator when cannot connect to server instead of meaningful error [Bug] NullReferenceException in SocketConnectionInitiator for UnixDomainSocket when cannot connect to server instead of meaningful error Feb 27, 2024
@HongGit
Copy link
Contributor

HongGit commented Feb 27, 2024

@imcarolwang can you please investigate and come up with a PR? Please make sure it throws EndPointNotFound exception, the call to ConvertConnectException should pass in SocketException, not lastException, and add unit test as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants