RPC error with MQTTv5 and QoS2
See original GitHub issueDescribe the bug
I started using RPC and developed a custom client based on your RPC extension. Without specifying a MQTT protocol version, everything works as expected.
However to be able to use the new UserProperties of the MQTT message, I specified the protocol version v5 in the client options:
.WithProtocolVersion(MqttProtocolVersion.V500)
After changing the protocol version to v5, the server is logging an error (please see attached log below) and the second RPC call is timing out / client is disconnected.
This problem seems to be related to QoS2 I use for the RPC messages. If I switch to QoS0, this error does not occur.
Which project is your bug related to?
- ManagedClient / RPC
- Server
Additional context / logging
Server
[DEBUG] 2019-08-08 10:11:01 - Client '127.0.0.1:53942' accepted by TCP listener '0.0.0.0:1883, ipv4'.
[DEBUG] 2019-08-08 10:11:01 - RX (47 bytes) <<< Connect: [ClientId=a03bffc41eae40fda49690c8f9c68fe9] [Username=] [Password=] [KeepAlivePeriod=15] [CleanSession=True]
[DEBUG] 2019-08-08 10:11:01 - Created a new session for client 'a03bffc41eae40fda49690c8f9c68fe9'.
[DEBUG] 2019-08-08 10:11:01 - MQTT: Client a03bffc41eae40fda49690c8f9c68fe9 connected
[ INFO] 2019-08-08 10:11:02 - Client 'a03bffc41eae40fda49690c8f9c68fe9': Session started.
[DEBUG] 2019-08-08 10:11:02 - TX (5 bytes) >>> ConnAck: [ReturnCode=ConnectionAccepted] [ReasonCode=Success] [IsSessionPresent=False]
[DEBUG] 2019-08-08 10:11:02 - RX (67 bytes) <<< Subscribe: [PacketIdentifier=1] [TopicFilters=Geminos.RPC/38838db0dad847e9a0220b4d9993512f/Login/response@ExactlyOnce]
[DEBUG] 2019-08-08 10:11:02 - TX (6 bytes) >>> SubAck: [PacketIdentifier=1] [ReturnCodes=SuccessMaximumQoS2] [ReasonCode=GrantedQoS2]
[DEBUG] 2019-08-08 10:11:02 - RX (323 bytes) <<< Publish: [Topic=Geminos.RPC/38838db0dad847e9a0220b4d9993512f/Login] [Payload.Length=266] [QoSLevel=ExactlyOnce] [Dup=False] [Retain=False] [PacketIdentifier=2]
[DEBUG] 2019-08-08 10:11:02 - TX (7 bytes) >>> PubRec: [PacketIdentifier=2] [ReasonCode=Success]
[DEBUG] 2019-08-08 10:11:02 - MQTT: Message from "a03bffc41eae40fda49690c8f9c68fe9": "Geminos.RPC/38838db0dad847e9a0220b4d9993512f/Login"
[DEBUG] 2019-08-08 10:11:02 - RX (4 bytes) <<< PubRel: [PacketIdentifier=2] [ReasonCode=Success]
[DEBUG] 2019-08-08 10:11:02 - TX (4 bytes) >>> PubComp: [PacketIdentifier=2] [ReasonCode=Success]
[DEBUG] 2019-08-08 10:11:02 - Queued application message with topic 'Geminos.RPC/38838db0dad847e9a0220b4d9993512f/Login/response' (ClientId: a03bffc41eae40fda49690c8f9c68fe9).
[DEBUG] 2019-08-08 10:11:02 - TX (447 bytes) >>> Publish: [Topic=Geminos.RPC/38838db0dad847e9a0220b4d9993512f/Login/response] [Payload.Length=380] [QoSLevel=ExactlyOnce] [Dup=False] [Retain=False] [PacketIdentifier=1]
[DEBUG] 2019-08-08 10:11:02 - RX (66 bytes) <<< Unsubscribe: [PacketIdentifier=3] [TopicFilters=Geminos.RPC/38838db0dad847e9a0220b4d9993512f/Login/response]
[DEBUG] 2019-08-08 10:11:02 - TX (6 bytes) >>> UnsubAck: [PacketIdentifier=3] [ReasonCodes=Success]
[DEBUG] 2019-08-08 10:11:02 - RX (7 bytes) <<< PubRec: [PacketIdentifier=1] [ReasonCode=Success]
[DEBUG] 2019-08-08 10:11:02 - RX (77 bytes) <<< Subscribe: [PacketIdentifier=4] [TopicFilters=Geminos.RPC/a1699c2022be47d585fee532c678b61c/GetTransactions/response@ExactlyOnce]
[DEBUG] 2019-08-08 10:11:02 - TX (6 bytes) >>> SubAck: [PacketIdentifier=4] [ReturnCodes=SuccessMaximumQoS2] [ReasonCode=GrantedQoS2]
[ WARN] 2019-08-08 10:11:02 - Sending publish packet failed: Communication exception (ClientId: a03bffc41eae40fda49690c8f9c68fe9). MQTTnet.Exceptions.MqttCommunicationException: The ReasonCode must be set for MQTT version 5. ---> MQTTnet.Exceptions.MqttProtocolViolationException: The ReasonCode must be set for MQTT version 5.
bei MQTTnet.Formatter.V5.MqttV500PacketEncoder.ThrowReasonCodeNotSetException()
bei MQTTnet.Formatter.V5.MqttV500PacketEncoder.EncodePubRelPacket(MqttPubRelPacket packet, IMqttPacketWriter packetWriter)
bei MQTTnet.Formatter.V5.MqttV500PacketEncoder.Encode(MqttBasePacket packet)
bei MQTTnet.Adapter.MqttChannelAdapter.<SendPacketAsync>d__34.MoveNext()
--- Ende der internen Ausnahmestapelüberwachung ---
bei MQTTnet.Adapter.MqttChannelAdapter.WrapException(Exception exception)
bei MQTTnet.Adapter.MqttChannelAdapter.<SendPacketAsync>d__34.MoveNext()
--- Ende der Stapelüberwachung vom vorhergehenden Ort, an dem die Ausnahme ausgelöst wurde ---
bei System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
bei System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
bei MQTTnet.Server.MqttClientConnection.<SendAsync>d__41.MoveNext()
--- Ende der Stapelüberwachung vom vorhergehenden Ort, an dem die Ausnahme ausgelöst wurde ---
bei System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
bei MQTTnet.Server.MqttClientConnection.<SendPendingPacketsAsync>d__40.MoveNext()
[DEBUG] 2019-08-08 10:11:02 - RX (236 bytes) <<< Publish: [Topic=Geminos.RPC/a1699c2022be47d585fee532c678b61c/GetTransactions] [Payload.Length=169] [QoSLevel=ExactlyOnce] [Dup=False] [Retain=False] [PacketIdentifier=5]
[DEBUG] 2019-08-08 10:11:02 - TX (7 bytes) >>> PubRec: [PacketIdentifier=5] [ReasonCode=Success]
[DEBUG] 2019-08-08 10:11:02 - Client 'a03bffc41eae40fda49690c8f9c68fe9': Stopped checking keep alive timeout.
[ INFO] 2019-08-08 10:11:02 - Client 'a03bffc41eae40fda49690c8f9c68fe9': Session stopped.
[DEBUG] 2019-08-08 10:11:02 - MQTT: Message from "a03bffc41eae40fda49690c8f9c68fe9": "Geminos.RPC/a1699c2022be47d585fee532c678b61c/GetTransactions"
[DEBUG] 2019-08-08 10:11:02 - Session for client 'a03bffc41eae40fda49690c8f9c68fe9' deleted.
[DEBUG] 2019-08-08 10:11:02 - MQTT: Client a03bffc41eae40fda49690c8f9c68fe9 disconnected
[DEBUG] 2019-08-08 10:11:02 - Client '127.0.0.1:53942' disconnected at TCP listener '0.0.0.0:1883, ipv4'.
Client
[ INFO] 2019-08-08 10:11:01 - Started
[DEBUG] 2019-08-08 10:11:01 - Trying to connect with server 'localhost:1883' (Timeout=00:00:10).
[DEBUG] 2019-08-08 10:11:01 - Connection with server established.
[DEBUG] 2019-08-08 10:11:01 - Start receiving packets.
[DEBUG] 2019-08-08 10:11:01 - TX (47 bytes) >>> Connect: [ClientId=a03bffc41eae40fda49690c8f9c68fe9] [Username=] [Password=] [KeepAlivePeriod=15] [CleanSession=True]
[DEBUG] 2019-08-08 10:11:02 - RX (5 bytes) <<< ConnAck: [ReturnCode=] [ReasonCode=Success] [IsSessionPresent=False]
[DEBUG] 2019-08-08 10:11:02 - Authenticated MQTT connection with server established.
[ INFO] 2019-08-08 10:11:02 - Connected.
[DEBUG] 2019-08-08 10:11:02 - Start sending keep alive packets.
[DEBUG] 2019-08-08 10:11:02 - TX (67 bytes) >>> Subscribe: [PacketIdentifier=1] [TopicFilters=Geminos.RPC/38838db0dad847e9a0220b4d9993512f/Login/response@ExactlyOnce]
[DEBUG] 2019-08-08 10:11:02 - RX (6 bytes) <<< SubAck: [PacketIdentifier=1] [ReturnCodes=] [ReasonCode=GrantedQoS2]
[DEBUG] 2019-08-08 10:11:02 - TX (324 bytes) >>> Publish: [Topic=Geminos.RPC/38838db0dad847e9a0220b4d9993512f/Login] [Payload.Length=266] [QoSLevel=ExactlyOnce] [Dup=False] [Retain=False] [PacketIdentifier=2]
[DEBUG] 2019-08-08 10:11:02 - RX (7 bytes) <<< PubRec: [PacketIdentifier=2] [ReasonCode=Success]
[DEBUG] 2019-08-08 10:11:02 - TX (4 bytes) >>> PubRel: [PacketIdentifier=2] [ReasonCode=Success]
[DEBUG] 2019-08-08 10:11:02 - RX (4 bytes) <<< PubComp: [PacketIdentifier=2] [ReasonCode=Success]
[DEBUG] 2019-08-08 10:11:02 - RX (446 bytes) <<< Publish: [Topic=Geminos.RPC/38838db0dad847e9a0220b4d9993512f/Login/response] [Payload.Length=380] [QoSLevel=ExactlyOnce] [Dup=False] [Retain=False] [PacketIdentifier=1]
[DEBUG] 2019-08-08 10:11:02 - TX (66 bytes) >>> Unsubscribe: [PacketIdentifier=3] [TopicFilters=Geminos.RPC/38838db0dad847e9a0220b4d9993512f/Login/response]
[DEBUG] 2019-08-08 10:11:02 - TX (7 bytes) >>> PubRec: [PacketIdentifier=1] [ReasonCode=Success]
[DEBUG] 2019-08-08 10:11:02 - RX (6 bytes) <<< UnsubAck: [PacketIdentifier=3] [ReasonCodes=Success]
[DEBUG] 2019-08-08 10:11:02 - TX (77 bytes) >>> Subscribe: [PacketIdentifier=4] [TopicFilters=Geminos.RPC/a1699c2022be47d585fee532c678b61c/GetTransactions/response@ExactlyOnce]
[DEBUG] 2019-08-08 10:11:02 - RX (6 bytes) <<< SubAck: [PacketIdentifier=4] [ReturnCodes=] [ReasonCode=GrantedQoS2]
[DEBUG] 2019-08-08 10:11:02 - TX (237 bytes) >>> Publish: [Topic=Geminos.RPC/a1699c2022be47d585fee532c678b61c/GetTransactions] [Payload.Length=169] [QoSLevel=ExactlyOnce] [Dup=False] [Retain=False] [PacketIdentifier=5]
[DEBUG] 2019-08-08 10:11:02 - RX (7 bytes) <<< PubRec: [PacketIdentifier=5] [ReasonCode=Success]
[DEBUG] 2019-08-08 10:11:02 - TX (4 bytes) >>> PubRel: [PacketIdentifier=5] [ReasonCode=Success]
[ WARN] 2019-08-08 10:11:02 - MQTT communication exception while receiving packets. MQTTnet.Exceptions.MqttCommunicationException: Eine vorhandene Verbindung wurde vom Remotehost geschlossen ---> System.Net.Sockets.SocketException: Eine vorhandene Verbindung wurde vom Remotehost geschlossen
bei System.Net.Sockets.Socket.EndReceive(IAsyncResult asyncResult)
bei System.Net.Sockets.NetworkStream.EndRead(IAsyncResult asyncResult)
--- Ende der Stapelüberwachung vom vorhergehenden Ort, an dem die Ausnahme ausgelöst wurde ---
bei System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
bei MQTTnet.Implementations.MqttTcpChannel.<ReadAsync>d__17.MoveNext()
--- Ende der Stapelüberwachung vom vorhergehenden Ort, an dem die Ausnahme ausgelöst wurde ---
bei System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
bei System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
bei MQTTnet.Formatter.MqttPacketReader.<ReadFixedHeaderAsync>d__3.MoveNext()
--- Ende der Stapelüberwachung vom vorhergehenden Ort, an dem die Ausnahme ausgelöst wurde ---
bei System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
bei System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
bei MQTTnet.Adapter.MqttChannelAdapter.<ReceiveAsync>d__37.MoveNext()
--- Ende der Stapelüberwachung vom vorhergehenden Ort, an dem die Ausnahme ausgelöst wurde ---
bei System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
bei System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
bei MQTTnet.Adapter.MqttChannelAdapter.<ReceivePacketAsync>d__35.MoveNext()
--- Ende der internen Ausnahmestapelüberwachung ---
bei MQTTnet.Adapter.MqttChannelAdapter.WrapException(Exception exception)
bei MQTTnet.Adapter.MqttChannelAdapter.<ReceivePacketAsync>d__35.MoveNext()
--- Ende der Stapelüberwachung vom vorhergehenden Ort, an dem die Ausnahme ausgelöst wurde ---
bei System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
bei System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
bei MQTTnet.Client.MqttClient.<TryReceivePacketsAsync>d__48.MoveNext()
Issue Analytics
- State:
- Created 4 years ago
- Comments:7
Top Results From Across the Web
RPC error with MQTTv5 and QoS2 · Issue #737
Describe the bug I started using RPC and developed a custom client based on your RPC extension. Without specifying a MQTT protocol version, ......
Read more >Untitled
I would like to use RPC for communication between fog nodes. ... want to use … where is paducah ky located RPC error...
Read more >Publish/subscribe AWS IoT Core MQTT messages
Send and receive messages to AWS IoT Core MQTT topics to communicate with the AWS ... bool OnErrorCallback(RpcError error) override { // Handle...
Read more >Turning MQTT v5 inside out
MQTT is a Client Server publish/subscribe messaging transport protocol. It is light weight, open, simple,.
Read more >Paho MQTT 5 - Apache Camel
Communicate with MQTT message brokers using Eclipse Paho MQTT v5 Client. ... Allows for bridging the consumer to the Camel routing Error Handler, ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

I was able to reproduce and fixed it. It will be released with the upcoming 3.0.7.
@chkr1011
Hi,
is it possible that this bug still occurs? I have exactely the same issues with a .NET Core 3.1 Client-Application.
Maybe MqttClientConnection.cs:466 is the problem
IS
SHOULD BE (?)
To be honest I can’t debug it myself, because when adding the MQTT-Projects to my project there are some compile errors due to missing packages/features (I guess UWP) and I don’t know how to fix that.
kind regards