# After deploy flow containing mqtt node, new connection is created, old connection remains open

**URL:** https://discourse.nodered.org/t/after-deploy-flow-containing-mqtt-node-new-connection-is-created-old-connection-remains-open/61928
**Category:** General
**Tags:** mqtt
**Created:** [28 April 2022 15:03 UTC](https://discourse.nodered.org/t/after-deploy-flow-containing-mqtt-node-new-connection-is-created-old-connection-remains-open/61928 "2022-04-28T15:03:00Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![alexwala](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/alexwala/32/60756_2.png) [@alexwala](https://discourse.nodered.org/u/alexwala)
#### Post date: [28 April 2022 15:03 UTC](https://discourse.nodered.org/t/after-deploy-flow-containing-mqtt-node-new-connection-is-created-old-connection-remains-open/61928/1 "2022-04-28T15:03:00Z")

</div>

Having a simple flow with a mqtt node (broker clientId set to autogenerated, port 8883).

After first deploy there is exactly one connection to the mqtt broker.  
(sudo netstat -nputw | grep 8883)

With each subsequent deployment the number of connections increases, as always a new connection is created and the old one is not disconnected...

If using a fixed clientId the issue does not occur - the number of connections is always 1.

using node-red v2.2.2

---

<div class="post-metadata">

### Author: ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)
#### Post date: [28 April 2022 15:07 UTC](https://discourse.nodered.org/t/after-deploy-flow-containing-mqtt-node-new-connection-is-created-old-connection-remains-open/61928/2 "2022-04-28T15:07:27Z")

</div>

What broker are you using and how have you configured the connection?

---

<div class="post-metadata">

### Author: ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)
#### Post date: [28 April 2022 15:09 UTC](https://discourse.nodered.org/t/after-deploy-flow-containing-mqtt-node-new-connection-is-created-old-connection-remains-open/61928/3 "2022-04-28T15:09:40Z")

</div>

I suspect it is the very same issue am working on right now.

Thanks for letting us know.

I'll keep you posted when a solution is found.

PS: In the mean time - use "Modified Nodes" method to minimise the impact (especially if you are NOT modifying an MQTT node) because "Full" causes all nodes (even ones you havent touched) to be re-created.

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/0/604fe568f6113159e92ae0859882ba8766058950.png)

---

<div class="post-metadata">

### Author: ![alexwala](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/alexwala/32/60756_2.png) [@alexwala](https://discourse.nodered.org/u/alexwala)
#### Post date: [2 May 2022 06:34 UTC](https://discourse.nodered.org/t/after-deploy-flow-containing-mqtt-node-new-connection-is-created-old-connection-remains-open/61928/4 "2022-05-02T06:34:48Z")

</div>

tried with different broker's (hivemq, mosquitto)

---

<div class="post-metadata">

### Author: ![alexwala](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/alexwala/32/60756_2.png) [@alexwala](https://discourse.nodered.org/u/alexwala)
#### Post date: [2 May 2022 06:35 UTC](https://discourse.nodered.org/t/after-deploy-flow-containing-mqtt-node-new-connection-is-created-old-connection-remains-open/61928/5 "2022-05-02T06:35:29Z")

</div>

thanks for suggestion with 'Modified Nodes'.

---

<div class="post-metadata">

### Author: ![greengolfer](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/greengolfer/32/28276_2.png) [@greengolfer](https://discourse.nodered.org/u/greengolfer)
#### Post date: [2 May 2022 13:19 UTC](https://discourse.nodered.org/t/after-deploy-flow-containing-mqtt-node-new-connection-is-created-old-connection-remains-open/61928/6 "2022-05-02T13:19:32Z")

</div>

> [@alexwala](#):
>
> tried with different broker's (hivemq, mosquitto)

QOS value and retain will change the behaviour. Upon losing the connection with a client the broker will maintain the connection for a while so that the same client reconnects it will find the messages waiting for him.  
When using the same client\_id you force reusing the same "queue" hence the same TCP connection on the broker.

---

<div class="post-metadata">

### Author: ![Barbudor](https://avatars.discourse-cdn.com/v4/letter/b/4af34b/32.png) [@Barbudor](https://discourse.nodered.org/u/Barbudor)
#### Post date: [3 May 2022 07:48 UTC](https://discourse.nodered.org/t/after-deploy-flow-containing-mqtt-node-new-connection-is-created-old-connection-remains-open/61928/7 "2022-05-03T07:48:11Z")

</div>

> [@greengolfer](#):
>
> QOS value and retain will change the behaviour.

I would say that "Clean session" is key  
I'm using either one of those 2 combinations:

- empty (automatic) client\_id and "Clean session" checked : the broker clear the client context in case of disconnection
- fixed client\_id and "Clean session" unchecked : the broker keeps the client context in case of temporary disconnection. **If a new connection comes with the same client\_id, the older one is closed by the broker.**

I don't say that other combinations are useless, just that I have no use-case for them.

So from your description it looks like the combination of "automatic client\_id" and "Clean session unchecked" leaves MQTT connection in the background that are neither closed by Node-RED nor the broker.

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)
#### Post date: [2 July 2022 07:48 UTC](https://discourse.nodered.org/t/after-deploy-flow-containing-mqtt-node-new-connection-is-created-old-connection-remains-open/61928/8 "2022-07-02T07:48:24Z")

</div>

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