aedes icon indicating copy to clipboard operation
aedes copied to clipboard

[bug] Aedes doesn't set the `dup` flag while resending the `PUBLISH` packet with QoS 2

Open tomekt-bolt opened this issue 3 years ago • 4 comments

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:

  1. 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.
  2. The program also publishes the message to the very same topic.
  3. 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.
  4. Upon re-connection, the client would be served the PUBLISH packet once more, with dup set to 0, 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.
  5. 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 missing DUP 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.

tomekt-bolt avatar Mar 26 '21 16:03 tomekt-bolt

Would you like to send a PR?

mcollina avatar Mar 26 '21 16:03 mcollina

Just to be clear - you mean a PR with a fix or a PR with steps demonstrating the problem ;)?

tomekt-bolt avatar Mar 26 '21 16:03 tomekt-bolt

PR with a fix @tomekt-bolt, with a test too :)

robertsLando avatar Mar 28 '21 09:03 robertsLando

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.

tomekt-bolt avatar Mar 30 '21 13:03 tomekt-bolt