aedes
aedes copied to clipboard
[bug] Aedes doesn't set the `dup` flag while resending the `PUBLISH` packet with QoS 2
System Information
- Aedes: 0.42.5
- NodeJS: v14.15.4
- OS: MacOS 10.15.7
- Arch: x86_64
- Persistence: redis
- Client: hivemq-mqtt-client 1.2.1
Describe the bug
Aedes doesn't set the dup
flag while resending the PUBLISH
packet with QoS 2 upon client re-connection.
To Reproduce Steps to reproduce the behavior:
- I've written a simple java program using the hivemq client that connects to the broker and subscribes to a given topic, with the automatic reconnection enabled on the client side.
- The program also publishes the message to the very same topic.
- I suspend the client program execution on a breakpoint right after the client reads the packet, but before the client acks it and wait until the broker closes the connection due to
keep alive timeout
. This simulates some network issue that the client was experiencing. - Upon re-connection, the client would be served the
PUBLISH
packet once more, withdup
set to0
, though the specification says: The DUP flag MUST be set to 1 by the Client or Server when it attempts to re-deliver a PUBLISH Packet. - The client then disconnects with a relevant error message
DUP flag must be set for a resent QoS 2 PUBLISH
and starts running in circles: reconnecting, receiving the same packet one more, disconnecting due to the missingDUP
flag, reconnecting once more etc.
Expected behavior
In point 4. the dup
flag should have been set to 1
according to the specification.
Additional context
I was able to reproduce the error using clean aedes-cli
with the redis backed persistence, no custom code of mine on the broker's side. Looking through aedes code, I haven't actually found any place where the DUP
flag would be set.
Would you like to send a PR?
Just to be clear - you mean a PR with a fix or a PR with steps demonstrating the problem ;)?
PR with a fix @tomekt-bolt, with a test too :)
I've added a PR, please have a look at your convenience. The tests are not passing atm, because it requires a complementary change in aedes-persistence
.