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

Will message not published when disconnecting an already connected client #1946

Closed
rpiper opened this issue Dec 12, 2020 · 3 comments
Closed
Milestone

Comments

@rpiper
Copy link

rpiper commented Dec 12, 2020

I'm testing MQTT Sparkplug B protocol using mosquitto broker, and I noticed that the Will message for clients is not being published by the broker when it disconnects an already connected client on reconnect. Sparkplug relies on Will message to indicate the end of a data session.

If a client connects with a Will message, then a second client connects with the same client Id as the first client, mosquitto is correctly closing the first connection, but it is not publishing the Will message of the first client.

The device I'm testing with is battery powered, and I can reproduce the bug by cycling power to the client while it is connected to the broker. When the client reconnects, mosquitto closes the old connection but does not publish the Will for the first connection.

I managed to fix the issue in my working copy with this one-line change to handle_connect.c:167

if(context->clean_start == true){
    sub__clean_session(found_context);
    context__send_will(found_context);
}
@ralight ralight added this to the 2.0.3 milestone Dec 12, 2020
@ralight
Copy link
Contributor

ralight commented Dec 12, 2020

Thanks @rpiper.

I'm not sure whether your suggestions is quite right for all cases. If a client has set a will delay interval, for instance, I do not believe the Will should be sent unconditionally. Leave it with me, I'll get it fixed for 2.0.3.

ralight added a commit that referenced this issue Dec 13, 2020
This was not happening for the case when the existing session wasn't
being continued.

Closes #1946. Thanks to Rory Piper.
@ralight
Copy link
Contributor

ralight commented Dec 13, 2020

I believe this is now fixed in the fixes branch. If you're able to confirm that it works for you that would be nice.

@rpiper
Copy link
Author

rpiper commented Dec 15, 2020

@ralight This fixes the issue. I have confirmed that the Will from previous connections is being published when the client reconnects with clean_start == true Thanks mate!

@rpiper rpiper closed this as completed Dec 15, 2020
fAuernigg pushed a commit to fAuernigg/mosquitto that referenced this issue Jan 4, 2021
This was not happening for the case when the existing session wasn't
being continued.

Closes eclipse#1946. Thanks to Rory Piper.
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 11, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants