Mqtt reestablishes always new sessions

I am using mosquitto - I have two NodeRed instance on the same machine, one works fine and one which always reconnects. I am using differen mqtt-client IDs, but I get always the following ping pong - the message came through - so functionality is good, but states switches always.
the mosquitto log shows the reconnection behaviour:

1656453851: New client connected from 127.0.0.1:47204 as mqttClientNodeRedTest (p2, c1, k60, u'mwmqtt').

Changing keepAlive to higher values - make no difference.
1656453855: New connection from 127.0.0.1:47206 on port 1883.
1656453855: Client mqttClientNodeRedTest already connected, closing old connection.
1656453855: New client connected from 127.0.0.1:47206 as mqttClientNodeRedTest (p2, c1, k60, u'mwmqtt').
1656453865: New connection from 127.0.0.1:47208 on port 1883.
1656453865: Client mqttClientNodeRedTest already connected, closing old connection.
1656453865: New client connected from 127.0.0.1:47208 as mqttClientNodeRedTest (p2, c1, k60, u'mwmqtt').
1656453867: New connection from 127.0.0.1:47210 on port 1883.
1656453867: Client mqttClientNodeRedTest already connected, closing old connection.
1656453867: New client connected from 127.0.0.1:47210 as mqttClientNodeRedTest (p2, c0, k60, u'mwmqtt').
1656453870: New connection from 127.0.0.1:47212 on port 1883.
1656453870: Client mqttClientNodeRedTest already connected, closing old connection.
1656453870: New client connected from 127.0.0.1:47212 as mqttClientNodeRedTest (p2, c1, k60, u'mwmqtt').

Increasing keepAlive does not change anything.

I suspect you have 2 identical MQTT configs on one of your node-red servers. There should be only one (or they should have different client ID)

I am using the same userid and password in both instances but I use already 2 different client IDs.

Look in the drop down where you select the MQTT config - how many entries do you see? Check both node-red servers.

I see in each instance only one configuration.

I even changed the userID of the test instance and it still keeps the old user-ID- Very strange.

1656457641: New client connected from 127.0.0.1:49140 as mqttClientNodeRedTest (p2, c1, k60, u'mwmqtt').
1656457641: New connection from 127.0.0.1:49142 on port 1883.
1656457641: Client mqttClientNodeRedTest already connected, closing old connection.
1656457641: New client connected from 127.0.0.1:49142 as mqttClientNodeRedTest (p2, c1, k60, u'mwmqtt').
1656457650: New connection from 127.0.0.1:49144 on port 1883.
1656457650: Client mqttClientNodeRedTest already connected, closing old connection.
1656457650: New client connected from 127.0.0.1:49144 as mqttClientNodeRedTest (p2, c0, k60, u'mwmqtt').
1656457656: New connection from 127.0.0.1:49146 on port 1883.
1656457656: Client mqttClientNodeRedTest already connected, closing old connection.
1656457656: New client connected from 127.0.0.1:49146 as mqttClientNodeRedTest (p2, c0, k60, u'mwmqttMSI').
1656457656: New connection from 127.0.0.1:49148 on port 1883.
1656457656: Client mqttClientNodeRedTest already connected, closing old connection.
1656457656: New client connected from 127.0.0.1:49148 as mqttClientNodeRedTest (p2, c1, k60, u'mwmqtt').
1656457656: New connection from 127.0.0.1:49150 on port 1883.
1656457656: Client mqttClientNodeRedTest already connected, closing old connection.
1656457656: New client connected from 127.0.0.1:49150 as mqttClientNodeRedTest (p2, c0, k60, u'mwmqtt').
1656457656: New connection from 127.0.0.1:49154 on port 1883.
1656457656: Client mqttClientNodeRedTest already connected, closing old connection.
1656457656: New client connected from 127.0.0.1:49154 as mqttClientNodeRedTest (p2, c1, k60, u'mwmqtt').

User mwmqtt is no longer used by - but it still connects with this user-ID. The new user (mwmqttMSI) is used in addition.


Using a clean session - makes no difference

Search your flow for mqttClientNodeRedTest how many are found?

Try restarting both node red servers, does it still happen?

So as I said, config is only found once:

However restarting both NodeRed instances seems that this solved the problem - for the moment. I have no explanation why.

So in general it works at the moment. After disabling and reenabling the mqtt-in Node - the node works but the status of the node is not updated correctly.

image

It says disconnected, but it is connected.

1656459117: New connection from 127.0.0.1:50616 on port 1883.
1656459117: Client mqttClientNodeRedTest already connected, closing old connection.
1656459117: New client connected from 127.0.0.1:50616 as mqttClientNodeRedTest (p2, c1, k60, u'mwmqttMSI').
1656459574: New connection from 127.0.0.1:50618 on port 1883.
1656459574: Client mqttClientNodeRedTest already connected, closing old connection.
1656459574: New client connected from 127.0.0.1:50618 as mqttClientNodeRedTest (p2, c1, k60, u'mwmqttMSI').

So it could be that disabling and reenabling the node - generates trouble ....

Only a complete restart of the NodeRed instance updates the status of the node correctly.

1656459117: Client mqttClientNodeRedTest already connected, closing old connection.
1656459117: New client connected from 127.0.0.1:50616 as mqttClientNodeRedTest (p2, c1, k60, u'mwmqttMSI').
1656459574: New connection from 127.0.0.1:50618 on port 1883.
1656459574: Client mqttClientNodeRedTest already connected, closing old connection.
1656459574: New client connected from 127.0.0.1:50618 as mqttClientNodeRedTest (p2, c1, k60, u'mwmqttMSI').
1656460151: Client mqttClientNodeRedTest closed its connection.
1656460175: New connection from 127.0.0.1:50620 on port 1883.
1656460175: New client connected from 127.0.0.1:50620 as mqttClientNodeRedTest (p2, c1, k60, u'mwmqttMSI').

Are you in a position to run node-red v3 beta. 3? The were a number of fixes around MQTT connecting/status and I'm fairly certain this is one of the issues fixed.

No I can't change the version, as those instances are not standalone versions. But as I found out that restarting NodeRed can temporarily fix this reconnection issue, I will wait until version 3 is available. Many thanks so far.