Return of the evil MQTT message recevied twice issue?

I have been working on a python MQTT receiver for devices that just can't handle NR (and the flows I want to run) in all of its glory. This has been going well so far until now. I have a python script that can run standalone or under systemd, supporting sdnotify protocol, etc. The basic subscribe and publish as been working fine. But the this morning, after working right for hours the fast few days... I am getting double messages in NR.

I restarted NR, I do not have retain set, and I have even added code to the python MQTT receiver to report that it sees and it does, and it is NOT sending anything twice. I then watched the MQTT broker, it is not sending anything twice. I then created a flow that uses and then does not use the json object node. But still see duplicate messages, the first one is fast, broker not doing much, but the second one is a few milliseconds later, a noticeable pause in the NR debug output, if that is any type of clue?

I read the thread on GitHub that states this had a fix applied for this? Suggestions to further analyze this? Really odd, no code changes in my python MQTT receiver, no changes to the broker, not even a stop and restart. So weird is the word at this point.

One more test, I added code to the python MQTT receiver to publish an informational message every time it starts/restarts just after the broker connection is achieved, that specific published message is not received twice. So code logic that does that invoke an active subscriber on the python MQTT receiver, does not double message generate.

The python code defaults to QoS 2, where NR defaults to no QoS, if that could be a factor? My understanding is with a QoS mismatch, the lowest common denominator is used thus no Qos?

Ok, more testing. NR is not in the loop on this specific issue, which makes sense given the discussion on GitHub on duplicate messages. I started sending test messages via the linux CLI, and a subscription to a given test topic (all topics are duplicating btw), duplicate messages generated by the broker. I stopped and restarted the broker, still getting the duplicate messages. Out of ideas at the moment.

Which broker are you using ?

@dceejay, Mosquitto. But I solved the issue. Only topics that matched the python MQTT listener were being duplicated. So I dug into the python MQTT listener log... the next step, since I had restarted the broker, NR, etc. And I noticed two different PIDs! I had only been running the python script manually, not as a service in testing. Well... LOL.

The python script as a service was stopped, but not disabled, at some point the pi device rebooted last night... have yet to figure out why... it is an old model b, oldest I have, so the power supply is ancient, whatever, the service was up. So I had a ghost of the python script running. Hence the double messages!

I have some code that does an exclusive file lock so the script can't be run twice at the same time... but that is protecting manual runs, it appears I need to make it include when script is running as service as well. That will avoid the ghost copy running as a service when I happen to be running manual testing. I could even have the first or second generate a SIGTERM to the other instance shuts down gracefully, but I digress.

Case of I made the python script smart... just not smart enough I guess!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.