Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MQTT message duplicated after automatic reconnection #120

Open
freyssin opened this issue Feb 24, 2020 · 0 comments
Open

MQTT message duplicated after automatic reconnection #120

freyssin opened this issue Feb 24, 2020 · 0 comments

Comments

@freyssin
Copy link

We have written a simple test that publishes QoS2 messages on a topic with a durable session (cleanSession= false). This test uses the FuseSource client through the callback API, with automatic reconnection feature. This test works correctly in the absence of failure, but we sometimes detect duplicated messages when network deconnections occur.

In the table below we reproduce the sequence of messages before and after the network failure (If necessary we have a wireshark capture of this sequence). As explained below it seems that the problem comes from the takeover of the client.

Client (frames sent) Server (frames sent)
PUBLISH #44  
  PUBREC #44
PUBREL #44  
===== Network failure ===== ===== Network failure =====
CONNECT  
  CONNACK
PUBLISH #44  
SUBSCRIBE #3  
  PUBREC #44
PUBREL #44  
  PUBCOMP #44
  SUBACK #3

When a failure is detected, the protocol flow should normally retry from the last unacknowledged protocol message (either PUBLISH or PUBREL). The MQTT 3.1.1 specification in section 4.3.3 states that: "In the QoS 2 delivery protocol, the Sender MUST NOT re-send the PUBLISH once it has sent the corresponding PUBREL packet.". We believe we are exactly in that case.

In the case above it seems that the client sends the PUBLISH #44 again while it has obviously received the corresponding PUBREC and sent the PUBREL.

When the server receives the PUBREL, it releases all persistency related to the message #44. So when it receives the PUBLISH #44 message again, it interprets the message as new. This results in the duplication of the message to the different subscribers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant