# MQTT Node frequently connect disconnect with azure iothub

**URL:** <https://discourse.nodered.org/t/mqtt-node-frequently-connect-disconnect-with-azure-iothub/64420>\
**Category:** General\
**Tags:** mqtt\
**Created:** [27 June 2022 13:31 UTC](https://discourse.nodered.org/t/mqtt-node-frequently-connect-disconnect-with-azure-iothub/64420 "2022-06-27T13:31:04Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![ibsoftweb](https://avatars.discourse-cdn.com/v4/letter/i/c4cdca/32.png) [@ibsoftweb](https://discourse.nodered.org/u/ibsoftweb)\
**Post date:** [27 June 2022 13:31 UTC](https://discourse.nodered.org/t/mqtt-node-frequently-connect-disconnect-with-azure-iothub/64420/1 "2022-06-27T13:31:04Z")

</div>

Hello Experts

I am facing issue mqtt connection issue. I am creating mqtt object in function node, I dont see way to disconnect or destroy mqtt connection, on redeploy of flow when I try connect method its get connected but seems like in memory there are two mqtt connection get created hence there is race condition in both to acquire connection. If I restart node and then try connection it works well

So is there way to disconnect existing mqtt connection? Is there any other way to dispose mqtt object? The way it does when restart node?

This is my flow.

 ![nodrederror](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/c/fc6bb80f53510544ea640e4fcfabdcdf795140e7.png)

---

<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:** [27 June 2022 15:02 UTC](https://discourse.nodered.org/t/mqtt-node-frequently-connect-disconnect-with-azure-iothub/64420/2 "2022-06-27T15:02:07Z")

</div>

Hi and welcome.

As you are DIY (doing it yourself) in a function node instead of using the built in MQTT nodes, it is difficult for regular users to help. I can clearly see what your issue is but would take me a fair bit of time to explain and is ultimately pointless as the the built in MQTT node supports dynamic connect/disconnect (as is documented in its built in help) - you should try that before asking about a DIY solution.

---

<div class="post-metadata">

**Author:** ![ibsoftweb](https://avatars.discourse-cdn.com/v4/letter/i/c4cdca/32.png) [@ibsoftweb](https://discourse.nodered.org/u/ibsoftweb)\
**Post date:** [28 June 2022 11:17 UTC](https://discourse.nodered.org/t/mqtt-node-frequently-connect-disconnect-with-azure-iothub/64420/3 "2022-06-28T11:17:20Z")

</div>

Actually with mqtt node I was facing same issue so was trying with DIY

Here is with mqtt node, it keep switching connect/disconnect.

 ![mqttnoderror](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/e/fee97209147b50a421987f8443338b9fc7df9486.png)

---

<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 June 2022 11:20 UTC](https://discourse.nodered.org/t/mqtt-node-frequently-connect-disconnect-with-azure-iothub/64420/4 "2022-06-28T11:20:47Z")

</div>

> [@ibsoftweb](#):
>
> Here is with mqtt node, it keep switching connect/disconnect.

There is a number of fixes in Node-RED v3.0.0-beta.3 around MQTT (and will eventuially make it into Node-red 2.x stream)

So perhaps you might want to try the beta?

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/a/ba0aa877eaf6945aa7b0d4a45f48cd63de7a0370.png)

---

<div class="post-metadata">

**Author:** ![ibsoftweb](https://avatars.discourse-cdn.com/v4/letter/i/c4cdca/32.png) [@ibsoftweb](https://discourse.nodered.org/u/ibsoftweb)\
**Post date:** [28 June 2022 12:15 UTC](https://discourse.nodered.org/t/mqtt-node-frequently-connect-disconnect-with-azure-iothub/64420/5 "2022-06-28T12:15:41Z")

</div>

> [@Steve-Mcl](#):
>
> Node-RED v3.0.0-beta.3

Will try that for sure, but existing system having 2.x will have this issue right?

---

<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 June 2022 12:21 UTC](https://discourse.nodered.org/t/mqtt-node-frequently-connect-disconnect-with-azure-iothub/64420/6 "2022-06-28T12:21:06Z")

</div>

Maybe. Maybe not. All I can say is that in certain circumstances the MQTT node can get locked up for various reasons. I don't know what you did so cannot say for certain if the fixes cover your use case. What I can say is that it is much more stable in v3 beta.

---

<div class="post-metadata">

**Author:** ![ibsoftweb](https://avatars.discourse-cdn.com/v4/letter/i/c4cdca/32.png) [@ibsoftweb](https://discourse.nodered.org/u/ibsoftweb)\
**Post date:** [28 June 2022 12:24 UTC](https://discourse.nodered.org/t/mqtt-node-frequently-connect-disconnect-with-azure-iothub/64420/7 "2022-06-28T12:24:34Z")

</div>

ok no problem. For my it seems like some issue, as I have created simple flow having mqtt connection, it works will until I do some changes in deploy. The only thing is my mqtt node dynamic and its not auto connected. Same thing with DIY. In both case I see same behavior.

I will try with v3 beta and post here conclusion, hopefully it will be positive 🙂

Imran

---

<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:** [27 August 2022 12:24 UTC](https://discourse.nodered.org/t/mqtt-node-frequently-connect-disconnect-with-azure-iothub/64420/8 "2022-08-27T12:24:59Z")

</div>

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