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

Handling PubRel when reconnecting to existing session #664

Open
swanandx opened this issue Jul 22, 2023 · 2 comments
Open

Handling PubRel when reconnecting to existing session #664

swanandx opened this issue Jul 22, 2023 · 2 comments

Comments

@swanandx
Copy link
Member

swanandx commented Jul 22, 2023

Expected Behavior

We should reply with PubComp for PubRel

Current Behavior

Client will disconnect with error "Unsolicited pubrel packet"

Failure Information (for bugs)

This issue is a little hard to reproduce, as we have to stop before sending PubComp

image

One method to reproduce/test:

  • clone rumqttc repo
  • ignore the incoming pubrel ( basically return early from this function )
fn handle_incoming_pubrel(&mut self, pubrel: &PubRel) -> Result<(), StateError> {
    return Ok(());
    __rest of the body__
}
  • use any example to publish some QoS2 message ( with clean session false! ).
  • stop / close the example.
  • restore the incoming pubrel function
fn handle_incoming_pubrel(&mut self, pubrel: &PubRel) -> Result<(), StateError> {
    // return Ok(()); ( remove this line! )
    __rest of the body__
}
  • re-run the example

Context

The PubRel packets which haven't received the PubComp yet, are treated as unacknowledged, and are resend on reconnection with clean session false and if session is present. ( reference )

When a client disconnects, we can't really store its state ( unless we use some disk persistence ). So there is no way if we can know whether to expect / not expect a PubRel packet when we reconnect.

Therefore, we should try to just reply with PubComp without worrying about whether we expect it or not. This should be fine as there is no standard for ordering of PubComp packets in OASIS standards.

  • Operating System: arch ( yes, i use arch btw )
  • Toolchain: stable-x86_64-unknown-linux-gnu ( rustc 1.71.0 )
  • rumqttc version: "0.22.0"

Would love to discuss more on this, or if you have any other better solution!

@sjorsdewit
Copy link

I think I have just caught this issue in production (with mosquitto as broker). Our client keeps disconnecting after reconnect, effectively getting stuck in a reconnect loop 'forever' as the broker keeps sending the PUBREL.

It appears that the paho client also had this same issue a few years ago: eclipse/paho.mqtt.python#284

@swanandx
Copy link
Member Author

swanandx commented Jan 8, 2024

Our client keeps disconnecting after reconnect, effectively getting stuck in a reconnect loop 'forever' as the broker keeps sending the PUBREL

if you are reconnecting by just polling eventloop again ( without terminating the program completely / dropping eventloop ), it should have pending pubrels in its pending

can you please provide minimal example if that is the case?

It appears that the paho client also had this same issue a few years ago

oh, thanks for pointing out, seems like they also didn't tackle this due to same reason 👀

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

2 participants