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
Persistence Issue - Mosquitto 2.0.15 and Paho MQTT C client - MQTT v5 #3014
Comments
what qos does the publishers use? |
Qos 1/2 for different scenarios but not 0. subscriptions are all confirmed to be worked and then client disconnect, reconnect with same ID shown above, nothing from mosquito about it being recognized, no messages from topics received that are not actively resubscribed to upon connect. |
mosquitto.conf:
I get equally many messages as i sent from the broker. I also took the time to make a tiny python script to test that it would receive queued messages without a new subscription, using the same client id; #!/usr/bin/python3
import paho.mqtt.client as mqtt
def on_connect(client, userdata, flags, reason_code, properties):
print(f"Connected {reason_code}")
def on_message(client, userdata, msg):
print(msg.topic+" "+str(msg.payload))
mqttc = mqtt.Client(mqtt.CallbackAPIVersion.VERSION2, client_id="subscriber1", protocol=5)
mqttc.on_connect = on_connect
mqttc.on_message = on_message
mqttc.connect("localhost", 1883, 60, clean_start=False)
mqttc.loop_forever() Intrestingly, this seems to exhibit your issue where messages stop comming. The only difference is that mosquitto_sub does another subscribe after connect. Oddly, this post-connection subscription is what you said your client does, just like mosquitto_sub. Edit:
this flow gives me the stored messages once between mosquitto sub and python test code. |
I'm not sure if you are saying you are seeing my same issue or not but let me use your format to explain mine and see if we can recreate.
To be clear, my scenario involves
|
Your log shows you are using MQTTV5. You need to set Session Expiry Interval explicitlyl in the CONNECT message. The default is 0 (zero) which means the session expires immediately after disconnect.
https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901048
Session Expiry Interval is a Property in MQTTV5 CONNECT.
mosquitto_sub sets the Session Expiry Interval per default if used with the -c option. (see mosquitto_sub —help)
… Am 09.03.2024 um 23:10 schrieb Ryan Wager ***@***.***>:
I'm not sure if you are saying you are seeing my same issue or not but let me use your format to explain mine and see if we can recreate.
Standup broker with persistence and config listed above.
Connect MQTTv5 client cleansession=false, with clientID 'B8A44F3205A4' to broker and subscribe to topic/test/1 and topic/test/2.
Publish messages to both topics, everything works as it should.
Reconnect client, same clientID, and this time only send a new subscription request to topic/test/1 (which you should already be subscribed to along with topic/test/2).
Logs show broker treats as new Client.
Client only receives messages on topic/test/1 and sees nothing on topic/test/2 (persistence should have maintained this topic subscription because of same ClientID, and not a cleansession.
To be clear, my scenario involves
Initial connection always conencts to say 5 different topics.
Mid session, I connect to lets say 2 more.
Disconnect.
Reconnect and re-subscribe to initial 5 topics (but do not resubscribe to the other 2).
No unsubscribe, always same client ID, persistence db growing, etc.
Messages to the extra 2 topics never reach the client after reconnect.
—
Reply to this email directly, view it on GitHub <#3014 (comment)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/AA6XHGMSCS5XM2QGOD63NVLYXOCETAVCNFSM6AAAAABENXXQROVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSOBWHE4TGNRSHA>.
You are receiving this because you are subscribed to this thread.
|
ah, right. cheers! |
Good sir, to say you are a lifesaver would be an understatement! Thank you!
I do have to say as well, was the Paho C client trying to keep this a
secret? Haha. I had to dive into the client code itself on github and
piece together how to get this to work. If they make setting cleanstart
true/false so easy, i have no idea why this critical component is not
documented or mentioned almost anywhere.
Here's the code that made it work for me, to save the next coder a little
trouble :). Thank you again Cristoph!
MQTTProperties props = MQTTProperties_initializer;
MQTTProperty property;
property.identifier = MQTTPROPERTY_CODE_SESSION_EXPIRY_INTERVAL;
property.value.integer4 = 3000;
MQTTProperties_add(&props, &property);
conn_opts.connectProperties = &props;
…On Sun, Mar 10, 2024 at 5:48 AM Tobias Assarsson ***@***.***> wrote:
ah, right.
subtle.
cheers!
—
Reply to this email directly, view it on GitHub
<#3014 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AD236V3LZOGCHBWFKJUWFCTYXQ27BAVCNFSM6AAAAABENXXQROVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSOBXGE4DCNZTGU>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
--
Ryan
|
Quick follow up question - For my use case, a controlled network with
controlled amounts of nodes, i really want this to NEVER expire (and i
understand the risks here).
Are there any settings for perpetual or what is the maximum this can be set
to?
Thank you again!!!
…On Sun, Mar 10, 2024 at 11:28 AM Ryan Wager ***@***.***> wrote:
Good sir, to say you are a lifesaver would be an understatement! Thank
you!
I do have to say as well, was the Paho C client trying to keep this a
secret? Haha. I had to dive into the client code itself on github and
piece together how to get this to work. If they make setting cleanstart
true/false so easy, i have no idea why this critical component is not
documented or mentioned almost anywhere.
Here's the code that made it work for me, to save the next coder a little
trouble :). Thank you again Cristoph!
MQTTProperties props = MQTTProperties_initializer;
MQTTProperty property;
property.identifier = MQTTPROPERTY_CODE_SESSION_EXPIRY_INTERVAL;
property.value.integer4 = 3000;
MQTTProperties_add(&props, &property);
conn_opts.connectProperties = &props;
On Sun, Mar 10, 2024 at 5:48 AM Tobias Assarsson ***@***.***>
wrote:
> ah, right.
> subtle.
>
> cheers!
>
> —
> Reply to this email directly, view it on GitHub
> <#3014 (comment)>,
> or unsubscribe
> <https://github.com/notifications/unsubscribe-auth/AD236V3LZOGCHBWFKJUWFCTYXQ27BAVCNFSM6AAAAABENXXQROVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSOBXGE4DCNZTGU>
> .
> You are receiving this because you authored the thread.Message ID:
> ***@***.***>
>
--
Ryan
--
Ryan
|
|
Thank you both, so much. Huge steps forward!
…On Mon, Mar 11, 2024 at 5:12 AM Tobias Assarsson ***@***.***> wrote:
If the Session Expiry Interval is 0xFFFFFFFF (UINT_MAX), the Session does
not expire.
—
Reply to this email directly, view it on GitHub
<#3014 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AD236V5NU3EH33GCAAX6V7TYXV7RDAVCNFSM6AAAAABENXXQROVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSOBYGA2DSOBRHE>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
--
Ryan
|
Thanks everyone, I'm closing this as complete. |
I have a system I am building that relies on MQTT for communication across nodes. I've done everything i can think of to make persistence work but no matter what whenever a client disconnects, and reconnects, with the exact same client ID, mosquitto with debug all treats them as a brand new connection. Will provide details below but I can provide anything else needed to help find if this is a bug or if I am just missing something.
The clients subscribe to topics with QOS1/2 and reply as they should until restart and then come back up and no longer get the messages.
Here's 2 examples of this occurring for one specific client. The clientID's are all unique because the clientID is their serial number. you can also see here that i am c0.
1709940654: New client connected from 192.168.128.123:50418 as B8A44F3205A4 (p5, c0, k20, u'baton').
1709942173: New client connected from 192.168.128.123:50498 as B8A44F3205A4 (p5, c0, k20, u'baton').
Here's the config file builder in C (sharing it but obviously have the file too)
The text was updated successfully, but these errors were encountered: