-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Description
Describe the bug
Connection to AWS using WebSockets fails on Mono
Which component is your bug related to?
- Client
I am having a strange issue with MQTTnet on Ubuntu using Mono, when using WebSockets. I have tested a few different scenarios using Windows, Linux and WebSockets/WebSockets4Net:
Windows 11, WebSockets, to either test.mosquitto.org:8081 or AWS (succes):
>> [24-3-2023 15:47:38] [6] [MqttClient] [Verbose]: Trying to connect with server 'test.mosquitto.org:8081'.
>> [24-3-2023 15:47:41] [12] [MqttClient] [Verbose]: Connection with server established.
>> [24-3-2023 15:47:41] [10] [MqttClient] [Verbose]: Start receiving packets.
>> [24-3-2023 15:47:41] [12] [MqttChannelAdapter] [Verbose]: TX (69 bytes) >>> Connect: [ClientId=xx-redacted-xx] [Username=] [Password=] [KeepAlivePeriod=15] [CleanSession=True]
>> [24-3-2023 15:47:41] [11] [MqttChannelAdapter] [Verbose]: RX (4 bytes) <<< ConnAck: [ReturnCode=ConnectionAccepted] [ReasonCode=Success] [IsSessionPresent=False]
>> [24-3-2023 15:47:41] [10] [MqttClient] [Verbose]: Authenticated MQTT connection with server established.
>> [24-3-2023 15:47:41] [10] [MqttClient] [Info]: Connected.
>> [24-3-2023 15:47:41] [9] [MqttClient] [Verbose]: Start sending keep alive packets.
Windows 11, WebSockets4Net, to either test.mosquitto.org:8081 or AWS (succes):
>> [24-3-2023 15:48:45] [6] [MqttClient] [Verbose]: Trying to connect with server 'test.mosquitto.org:8081'.
>> [24-3-2023 15:48:47] [9] [MqttClient] [Verbose]: Connection with server established.
>> [24-3-2023 15:48:47] [13] [MqttClient] [Verbose]: Start receiving packets.
>> [24-3-2023 15:48:47] [9] [MqttChannelAdapter] [Verbose]: TX (69 bytes) >>> Connect: [ClientId=xx-redacted-xx] [Username=] [Password=] [KeepAlivePeriod=15] [CleanSession=True]
>> [24-3-2023 15:48:47] [13] [MqttChannelAdapter] [Verbose]: RX (4 bytes) <<< ConnAck: [ReturnCode=ConnectionAccepted] [ReasonCode=Success] [IsSessionPresent=False]
>> [24-3-2023 15:48:47] [14] [MqttClient] [Verbose]: Authenticated MQTT connection with server established.
>> [24-3-2023 15:48:47] [14] [MqttClient] [Info]: Connected.
>> [24-3-2023 15:48:47] [9] [MqttClient] [Verbose]: Start sending keep alive packets.
Ubuntu 22.04, Mono 6.8.0.105, WebSockets, to test.mosquitto.org:8081 (succes):
>> [3/24/2023 3:50:01 PM] [6] [MqttClient] [Verbose]: Trying to connect with server 'test.mosquitto.org:8081'
>> [3/24/2023 3:50:02 PM] [11] [MqttClient] [Verbose]: Connection with server established
>> [3/24/2023 3:50:02 PM] [9] [MqttClient] [Verbose]: Start receiving packets
>> [3/24/2023 3:50:02 PM] [11] [MqttChannelAdapter] [Verbose]: TX (69 bytes) >>> Connect: [ClientId=xx-redacted-xx] [Username=] [Password=] [KeepAlivePeriod=15] [CleanSession=True
>> [3/24/2023 3:50:02 PM] [9] [MqttChannelAdapter] [Verbose]: RX (4 bytes) <<< ConnAck: [ReturnCode=ConnectionAccepted] [ReasonCode=Success] [IsSessionPresent=False
>> [3/24/2023 3:50:02 PM] [8] [MqttClient] [Verbose]: Authenticated MQTT connection with server established
>> [3/24/2023 3:50:02 PM] [8] [MqttClient] [Info]: Connected
>> [3/24/2023 3:50:02 PM] [11] [MqttClient] [Verbose]: Start sending keep alive packets
Ubuntu 22.04, Mono 6.8.0.105, WebSockets, to AWS (fails):
>> [3/24/2023 3:52:50 PM] [6] [MqttClient] [Verbose]: Trying to connect with server 'iot.eu-west-1.xx-redacted-xx.com'
> [3/24/2023 3:52:50 PM] [8] [MqttClient] [Verbose]: Connection with server established
>> [3/24/2023 3:52:50 PM] [9] [MqttClient] [Verbose]: Start receiving packets
>> [3/24/2023 3:52:50 PM] [8] [MqttChannelAdapter] [Verbose]: TX (69 bytes) >>> Connect: [ClientId=xx-redacted-xx] [Username=] [Password=] [KeepAlivePeriod=15] [CleanSession=True
>> [3/24/2023 3:52:50 PM] [8] [MqttClient] [Verbose]: Disconnecting [Timeout=00:01:40
>> [3/24/2023 3:52:50 PM] [11] [MqttClient] [Warning]: Timeout while waiting for response packet (MqttConnAckPacket)
>> [3/24/2023 3:52:50 PM] [11] [MqttClient] [Error]: Error while connecting with server.
MQTTnet.Adapter.MqttConnectingFailedException: Error while authenticating. The operation has timed out. ---> MQTTnet.Exceptions.MqttCommunicationTimedOutException: The operation has timed out.
at MQTTnet.PacketDispatcher.MqttPacketAwaitable`1[TPacket].WaitOneAsync (System.Threading.CancellationToken cancellationToken) [0x00092] in <1d26aa7eaa5a4094a08c8933437012f1>:0
at MQTTnet.Client.MqttClient.SendAndReceiveAsync[TResponsePacket] (MQTTnet.Packets.MqttPacket requestPacket, System.Threading.CancellationToken cancellationToken) [0x001a3] in <1d26aa7eaa5a4094a08c8933437012f1>:0
at MQTTnet.Client.MqttClient.AuthenticateAsync (MQTTnet.Client.MqttClientOptions options, System.Threading.CancellationToken cancellationToken) [0x0008f] in <1d26aa7eaa5a4094a08c8933437012f1>:0
--- End of inner exception stack trace ---
at MQTTnet.Client.MqttClient.AuthenticateAsync (MQTTnet.Client.MqttClientOptions options, System.Threading.CancellationToken cancellationToken) [0x000cd] in <1d26aa7eaa5a4094a08c8933437012f1>:0
at MQTTnet.Client.MqttClient.ConnectAsync (MQTTnet.Client.MqttClientOptions options, System.Threading.CancellationToken cancellationToken) [0x00339] in <1d26aa7eaa5a4094a08c8933437012f1>:0
>> [3/24/2023 3:52:50 PM] [8] [MqttClient] [Verbose]: Disconnected from adapter
>> [3/24/2023 3:52:50 PM] [8] [MqttClient] [Info]: Disconnected
>> [3/24/2023 3:52:50 PM] [8] [MqttClient] [Verbose]: Stopped receiving packets
Ubuntu 22.04, Mono 6.8.0.105, WebSockets4Net, to test.mosquitto.org:8081 (fails):
>> [3/24/2023 3:54:06 PM] [6] [MqttClient] [Verbose]: Trying to connect with server 'test.mosquitto.org:8081'
>> [3/24/2023 3:54:06 PM] [11] [MqttClient] [Verbose]: Connection with server established
>> [3/24/2023 3:54:06 PM] [9] [MqttClient] [Verbose]: Start receiving packets
>> [3/24/2023 3:54:06 PM] [11] [MqttChannelAdapter] [Verbose]: TX (69 bytes) >>> Connect: [ClientId=xx-redacted-xx] [Username=] [Password=] [KeepAlivePeriod=15] [CleanSession=True
Ubuntu 22.04, Mono 6.8.0.105, WebSockets4Net, to AWS (fails):
>> [3/24/2023 3:55:10 PM] [6] [MqttClient] [Verbose]: Trying to connect with server 'iot.eu-west-1.xx-redacted-xx.com'
>> [3/24/2023 3:55:10 PM] [9] [MqttClient] [Verbose]: Connection with server established
>> [3/24/2023 3:55:10 PM] [9] [MqttChannelAdapter] [Verbose]: TX (69 bytes) >>> Connect: [ClientId=xx-redacted-xx] [Username=] [Password=] [KeepAlivePeriod=15] [CleanSession=True
>> [3/24/2023 3:55:10 PM] [8] [MqttClient] [Verbose]: Start receiving packets
Windows always works. But Mono only works with standard WebSockets and the mosquitto server. All other combinations do not (WebSockets to AWS fails, WebSockets4Net fails for both AWS and mosquitto).
Probably totally unrelated, but with Mono, the last ] is missing from the trace ("[CleanSession=True" instead of "[CleanSession=True]").