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

Linux - when Upgrading from version 4.3.3.952 to 4.3.4.1084 the client always raises the exception «None of the discovered or specified addresses match the socket address family» #1997

Closed
daframax opened this issue May 17, 2024 · 7 comments · Fixed by #1999
Labels
bug Something isn't working

Comments

@daframax
Copy link

daframax commented May 17, 2024

Describe the bug

Using the latest version on Linux (Mono) the Client always raises the MqttCommunicationException with the message: None of the discovered or specified addresses match the socket address family when trying to connect to Remote EndPoint.

Using Version 4.3.3.952 works fine.

Which component is your bug related to?

  • Client

To Reproduce

Steps to reproduce the behavior:

  1. Using version of MQTTnet v4.3.4.1084.
  2. Try to simply invoke Client.ConnectAsync(options)

Expected behavior

The client connects to the Broker.

Additional context / logging

MQTTnet.Exceptions.MqttCommunicationException: None of the discovered or specified addresses match the socket address family. ---> System.ArgumentException: None of the discovered or specified addresses match the socket address family.
  at System.Net.Sockets.SocketAsyncResult.CheckIfThrowDelayedException () [0x00014] in <a8a996a78a804d888710c9e2575d78c8>:0 
  at System.Net.Sockets.Socket.EndConnect (System.IAsyncResult asyncResult) [0x0002c] in <a8a996a78a804d888710c9e2575d78c8>:0 
  at System.Threading.Tasks.TaskFactory`1[TResult].FromAsyncCoreLogic (System.IAsyncResult iar, System.Func`2[T,TResult] endFunction, System.Action`1[T] endAction, System.Threading.Tasks.Task`1[TResult] promise, System.Boolean requiresSynchronization) [0x00019] in <d636f104d58046fd9b195699bcb1a744>:0 
--- End of stack trace from previous location where exception was thrown ---

  at MQTTnet.Implementations.CrossPlatformSocket.ConnectAsync (System.Net.EndPoint endPoint, System.Threading.CancellationToken cancellationToken) [0x000e9] in <b93c2f176a9c4aa59d4db05b60c0955f>:0 
  at MQTTnet.Implementations.MqttTcpChannel.ConnectAsync (System.Threading.CancellationToken cancellationToken) [0x00383] in <b93c2f176a9c4aa59d4db05b60c0955f>:0 
  at MQTTnet.Adapter.MqttChannelAdapter+<>c__DisplayClass30_0.<ConnectAsync>b__1 () [0x0009a] in <b93c2f176a9c4aa59d4db05b60c0955f>:0 
  at MQTTnet.Adapter.MqttChannelAdapter.ConnectAsync (System.Threading.CancellationToken cancellationToken) [0x001e1] in <b93c2f176a9c4aa59d4db05b60c0955f>:0 
   --- End of inner exception stack trace ---
  at MQTTnet.Adapter.MqttChannelAdapter.WrapAndThrowException (System.Exception exception) [0x00090] in <b93c2f176a9c4aa59d4db05b60c0955f>:0 
  at MQTTnet.Adapter.MqttChannelAdapter.ConnectAsync (System.Threading.CancellationToken cancellationToken) [0x00213] in <b93c2f176a9c4aa59d4db05b60c0955f>:0 
  at MQTTnet.Client.MqttClient.ConnectInternal (MQTTnet.Adapter.IMqttChannelAdapter channelAdapter, System.Threading.CancellationToken cancellationToken) [0x000f4] in <b93c2f176a9c4aa59d4db05b60c0955f>:0 
  at MQTTnet.Client.MqttClient.ConnectAsync (MQTTnet.Client.MqttClientOptions options, System.Threading.CancellationToken cancellationToken) [0x002ba] in <b93c2f176a9c4aa59d4db05b60c0955f>:0 
  at MQTTnet.Client.MqttClient.ConnectAsync (MQTTnet.Client.MqttClientOptions options, System.Threading.CancellationToken cancellationToken) [0x0059d] in <b93c2f176a9c4aa59d4db05b60c0955f>:0 

Note

No code provided as the issue is simply related to the ConnectAsync method.

@daframax daframax added the bug Something isn't working label May 17, 2024
@daframax daframax changed the title Linux - when Upgrading from version 4.3.3.952 to 4.3.4.1084 the client always raises the exception Linux - when Upgrading from version 4.3.3.952 to 4.3.4.1084 the client always raises the exception «None of the discovered or specified addresses match the socket address family» May 17, 2024
@chkr1011
Copy link
Collaborator

chkr1011 commented May 17, 2024

@daframax Are you using an DNS host address in the WithTcpServer method or an IP address (as string)?

@daframax
Copy link
Author

daframax commented May 17, 2024

Hello @chkr1011,
First of all thank you for the library: it is a great work.
I started using it from version 3.x

Regarding your question: I pass the host as string and the port as int.

@chkr1011 chkr1011 linked a pull request May 17, 2024 that will close this issue
@chkr1011
Copy link
Collaborator

@daframax Please try this version from mygetfeed and let me know if it works: https://www.myget.org/feed/mqttnet/package/nuget/MQTTnet/4.3.4.1116

@daframax
Copy link
Author

Thank you @chkr1011 I will try it and let you know as soon as possibile

@chkr1011
Copy link
Collaborator

I figured out that the issue is related to Mono. It handles the DnsEndpoint differently than .NET Framework does. When using the overload with host and port it works perfectly.

Build: 4.3.4.1133 contains the fix if you want to test.

I will add a workaround for that and release a new version soon.

@daframax
Copy link
Author

Hello @chkr1011 Thank you for your time.
I was about to report the same thing after testing the version 4.3.4.1116.
I noticed that one of differences between version 4.3.3.952 and 4.3.4.1084 was the ctor into the class CrossPlatformSocket. So I check the source code of the implementation of the class Socket.cs inside the mono repo on github and I noticed that there are differences:

Method socket.ConnectAsync(string host, int port) uses:

public IAsyncResult BeginConnect (string host, int port, AsyncCallback callback, object state)
		{
			ThrowIfDisposedAndClosed ();

			if (host == null)
				throw new ArgumentNullException ("host");
			if (addressFamily != AddressFamily.InterNetwork && addressFamily != AddressFamily.InterNetworkV6)
				throw new NotSupportedException ("This method is valid only for sockets in the InterNetwork and InterNetworkV6 families");
			if (port <= 0 || port > 65535)
				throw new ArgumentOutOfRangeException ("port", "Must be > 0 and < 65536");
			if (is_listening)
				throw new InvalidOperationException ();

			var sockares = new SocketAsyncResult (this, callback, state, SocketOperation.Connect) {
				Port = port
			};

			var dnsRequest = Dns.GetHostAddressesAsync (host);
			dnsRequest.ContinueWith (t => {
				if (t.IsFaulted)
					sockares.Complete (t.Exception.InnerException);
				else if (t.IsCanceled)
					sockares.Complete (new OperationCanceledException ());
				else {
					sockares.Addresses = t.Result;
					BeginMConnect (sockares);
				}
			}, TaskScheduler.Default);

			return sockares;
		}

Method socket.ConnectAsync(EndPoint endpoint) uses:

public IAsyncResult BeginConnect (EndPoint remoteEP, AsyncCallback callback, object state)
		{
			ThrowIfDisposedAndClosed ();

			if (remoteEP == null)
				throw new ArgumentNullException ("remoteEP");
			if (is_listening)
				throw new InvalidOperationException ();

			SocketAsyncResult sockares = new SocketAsyncResult (this, callback, state, SocketOperation.Connect) {
				EndPoint = remoteEP,
			};

			BeginSConnect (sockares);
			return sockares;
		}

I will test the version 4.3.4.1133

Thank you

@chkr1011
Copy link
Collaborator

Please test with the released 4.3.5 version. I experienced the same issue with one of my Android apps. So, I was able to fix it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants