question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Bug: ClientMessageQueueInterceptor breaks the broker due to QoS levels

See original GitHub issue

Describe the bug

If a Client A subscribes a topic with QoS 0 and a client B publishes with QoS 1 AND a ClientMessageQueueInterceptor is used, the broker throws an exception.

Which project is your bug related to?

  • Server

To Reproduce

Steps to reproduce the behavior:

  1. Using this version of MQTTnet ‘3.0.12’.
  2. Add a ClientMessageQueueInterceptor.
  3. Subscribe with a Client to a topic “A” and QoS 0
  4. Publish with a Client to topic “A” and QoS 1
  5. Exception is thrown (MqttCommunicationException)

Expected behavior

The usage of a ClientMessageQueueInterceptor should work correctly.

Additional context / logging

The following lines lead to the exception:

The thrown exceptions:

Message was published with QoS 1 but client subscribed with QoS 0:

MQTT Trace: Sending publish packet failed: Communication exception (ClientId: xy).
MQTTnet.Exceptions.MqttCommunicationException: Packet identifier must be empty if QoS == 0 [MQTT-2.3.1-5]. ---> MQTTnet.Exceptions.MqttProtocolViolationException: Packet identifier must be empty if QoS == 0 [MQTT-2.3.1-5].
   at MQTTnet.Formatter.V3.MqttV310PacketFormatter.EncodePublishPacket(MqttPublishPacket packet, IMqttPacketWriter packetWriter)
   at MQTTnet.Formatter.V3.MqttV310PacketFormatter.Encode(MqttBasePacket packet)
   at MQTTnet.Adapter.MqttChannelAdapter.<SendPacketAsync>d__33.MoveNext()
   --- End of inner exception stack trace ---
   at MQTTnet.Adapter.MqttChannelAdapter.WrapException(Exception exception)
   at MQTTnet.Adapter.MqttChannelAdapter.<SendPacketAsync>d__33.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at MQTTnet.Server.MqttClientConnection.<SendAsync>d__46.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at MQTTnet.Server.MqttClientConnection.<SendPendingPacketsAsync>d__45.MoveNext()

Message was published with QoS 0 but client subscribed with QoS 1:

MQTT Trace: Sending publish packet failed: Communication exception (ClientId: xy).
MQTTnet.Exceptions.MqttCommunicationException: Publish packet has no packet identifier. ---> MQTTnet.Exceptions.MqttProtocolViolationException: Publish packet has no packet identifier.
   at MQTTnet.Formatter.V3.MqttV310PacketFormatter.EncodePublishPacket(MqttPublishPacket packet, IMqttPacketWriter packetWriter)
   at MQTTnet.Formatter.V3.MqttV310PacketFormatter.Encode(MqttBasePacket packet)
   at MQTTnet.Adapter.MqttChannelAdapter.<SendPacketAsync>d__33.MoveNext()
   --- End of inner exception stack trace ---
   at MQTTnet.Adapter.MqttChannelAdapter.WrapException(Exception exception)
   at MQTTnet.Adapter.MqttChannelAdapter.<SendPacketAsync>d__33.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at MQTTnet.Server.MqttClientConnection.<SendAsync>d__46.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at MQTTnet.Server.MqttClientConnection.<SendPendingPacketsAsync>d__45.MoveNext()

Discussion

This is a bug which is very urgent for us and we would like to submit a Pull Request. We see the following possibilities:

  1. Don’t allow the interceptor to change the QoS level at all (means, just delete the line)
  2. Pass and the correct QoS level (means, if the interceptor doesn’t change something, the correct level as before is set)

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
chkr1011commented, Sep 17, 2020

@msallin I have no plans yet for a new release but I will release an RC soon so you can already make use of the latest changes.

Read more comments on GitHub >

github_iconTop Results From Across the Web

ClientMessageQueueInterceptor breaks the broker due to ...
Publish with a Client to topic "A" and QoS 1; Exception is thrown ( MqttCommunicationException ). Expected behavior. The usage of a ...
Read more >
What is MQTT Quality of Service (QoS) 0,1, & 2?
If the subscribing client defines a lower QoS level than the publishing client, the broker will transmit the message with the lower QoS...
Read more >
Broker Issues (Oracle GlassFish Message Queue 4.4.2 ...
This “bad version” warning indicates that the client should reconnect to the broker at a lower protocol level. When using a JDBC data...
Read more >
Understanding MQTT QOS Levels- Part 1
The QOS levels are a way of guaranteeing message delivery and they refer to the connection between a broker and a client.
Read more >
MQTT QoS Guide - Quality of Service 0, 1, 2 Explained
MQTT QoS is a level of service that serves as a consensus between a publisher and a broker on one hand, and the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found