# Dynamically Disable individual nodes

**URL:** <https://discourse.nodered.org/t/dynamically-disable-individual-nodes/92396>\
**Category:** Feature Requests\
**Created:** [15 October 2024 06:26 UTC](https://discourse.nodered.org/t/dynamically-disable-individual-nodes/92396 "2024-10-15T06:26:04Z")\
**Posts on this page:** 15\
**Page:** 2

<div class="post-metadata">

**Author:** ![KarolisL](https://avatars.discourse-cdn.com/v4/letter/k/a4c791/32.png) [@KarolisL](https://discourse.nodered.org/u/KarolisL)\
**Post date:** [15 October 2024 08:42 UTC](https://discourse.nodered.org/t/dynamically-disable-individual-nodes/92396/21 "2024-10-15T08:42:33Z")

</div>

Maybe I should create a separate topic? Because this one is for dynamic node disable

---

<div class="post-metadata">

**Author:** ![gregorius](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gregorius/32/73816_2.png) [@gregorius](https://discourse.nodered.org/u/gregorius)\
**Post date:** [15 October 2024 08:43 UTC](https://discourse.nodered.org/t/dynamically-disable-individual-nodes/92396/22 "2024-10-15T08:43:41Z")

</div>

Perhaps [msg.reset](https://github.com/node-red/node-red/blob/2854351909dee9f92597faba3f37239134294eec/packages/node_modules/%40node-red/nodes/core/network/31-tcpin.js#L414-L416) is what you want

---

<div class="post-metadata">

**Author:** ![GogoVega](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gogovega/32/71313_2.png) [@GogoVega](https://discourse.nodered.org/u/GogoVega)\
**Post date:** [15 October 2024 08:46 UTC](https://discourse.nodered.org/t/dynamically-disable-individual-nodes/92396/23 "2024-10-15T08:46:25Z")

</div>

In itself, you need to trigger the closing of your TCP node. So you can create a test code in one of your node that reacts to RED.httpAdmin (for example) and calls yourTcpNode.close(). I have never tried and the node will not be usable after that without a reboot.

---

<div class="post-metadata">

**Author:** ![GogoVega](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gogovega/32/71313_2.png) [@GogoVega](https://discourse.nodered.org/u/GogoVega)\
**Post date:** [15 October 2024 08:49 UTC](https://discourse.nodered.org/t/dynamically-disable-individual-nodes/92396/24 "2024-10-15T08:49:37Z")

</div>

As Matthias and me said there are only two possibilities at the moment:

- deployment to disable the node
- custom TCP node with button to trigger a close event

---

<div class="post-metadata">

**Author:** ![gregorius](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gregorius/32/73816_2.png) [@gregorius](https://discourse.nodered.org/u/gregorius)\
**Post date:** [15 October 2024 08:49 UTC](https://discourse.nodered.org/t/dynamically-disable-individual-nodes/92396/25 "2024-10-15T08:49:44Z")

</div>

> [@KarolisL](#):
>
> Because this one is for dynamic node disable

Won't bother, I doubt very much that a) that is the solution to your problem b) that anyone else would need this feature (see a)).

---

<div class="post-metadata">

**Author:** ![gregorius](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gregorius/32/73816_2.png) [@gregorius](https://discourse.nodered.org/u/gregorius)\
**Post date:** [15 October 2024 08:50 UTC](https://discourse.nodered.org/t/dynamically-disable-individual-nodes/92396/26 "2024-10-15T08:50:48Z")

</div>

> [@GogoVega](#):
>
> only two possibilities at the moment

What about [msg.reset](https://github.com/node-red/node-red/blob/2854351909dee9f92597faba3f37239134294eec/packages/node_modules/%40node-red/nodes/core/network/31-tcpin.js#L414-L416)

---

<div class="post-metadata">

**Author:** ![GogoVega](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gogovega/32/71313_2.png) [@GogoVega](https://discourse.nodered.org/u/GogoVega)\
**Post date:** [15 October 2024 08:56 UTC](https://discourse.nodered.org/t/dynamically-disable-individual-nodes/92396/27 "2024-10-15T08:56:27Z")

</div>

Yeah, maybe already there 🤔

 ![Capture d’écran 2024-10-15 à 10.56.09](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/a/3aadcbd973bee16136ae3e8cdca7a2416ae9ee1f.png)

---

<div class="post-metadata">

**Author:** ![KarolisL](https://avatars.discourse-cdn.com/v4/letter/k/a4c791/32.png) [@KarolisL](https://discourse.nodered.org/u/KarolisL)\
**Post date:** [15 October 2024 08:58 UTC](https://discourse.nodered.org/t/dynamically-disable-individual-nodes/92396/28 "2024-10-15T08:58:29Z")

</div>

msg.reset doesn't work because it drops connection but with another request it will be restored, where in reality after tcp listener is not available anymore it will generate a connection timeout error

so I could automate the test with msg.reset, then change msg.host and msg.port to get the same status messages

---

<div class="post-metadata">

**Author:** ![gregorius](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gregorius/32/73816_2.png) [@gregorius](https://discourse.nodered.org/u/gregorius)\
**Post date:** [15 October 2024 08:59 UTC](https://discourse.nodered.org/t/dynamically-disable-individual-nodes/92396/29 "2024-10-15T08:59:31Z")

</div>

> [@gregorius](#):
>
> msg.res.\_res.socket.destroy()

This actually works:

```auto
[{"id":"9ca116c3ccd7fca7","type":"http in","z":"cb92e457310576e3","name":"","url":"/suddendeath","method":"get","upload":false,"swaggerDoc":"","x":353,"y":482,"wires":[["846036026b9e42bf"]]},{"id":"846036026b9e42bf","type":"function","z":"cb92e457310576e3","name":"function 35","func":"msg.res._res.socket.destroy()\n\nreturn msg;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":592,"y":580,"wires":[[]]}]

```

produces this result when accessed with curl:

```sh
prompt> curl -v http://localhost:1880/suddendeath
* Trying 127.0.0.1...
* TCP_NODELAY set
* Connected to renderbox (127.0.0.1) port 1880 (#0)
> GET /suddendeath HTTP/1.1
> Host: localhost:1880
> User-Agent: curl/7.63.0
> Accept: */*
>
* Empty reply from server

```

---

<div class="post-metadata">

**Author:** ![gregorius](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gregorius/32/73816_2.png) [@gregorius](https://discourse.nodered.org/u/gregorius)\
**Post date:** [15 October 2024 09:03 UTC](https://discourse.nodered.org/t/dynamically-disable-individual-nodes/92396/30 "2024-10-15T09:03:40Z")

</div>

> [@KarolisL](#):
>
> after tcp listener is not available

you want to disable the tcp in node to simulate a missing tcp server? ok that's another kettle of fish.

---

<div class="post-metadata">

**Author:** ![KarolisL](https://avatars.discourse-cdn.com/v4/letter/k/a4c791/32.png) [@KarolisL](https://discourse.nodered.org/u/KarolisL)\
**Post date:** [15 October 2024 09:05 UTC](https://discourse.nodered.org/t/dynamically-disable-individual-nodes/92396/31 "2024-10-15T09:05:03Z")

</div>

That's correct

---

<div class="post-metadata">

**Author:** ![gregorius](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gregorius/32/73816_2.png) [@gregorius](https://discourse.nodered.org/u/gregorius)\
**Post date:** [15 October 2024 09:08 UTC](https://discourse.nodered.org/t/dynamically-disable-individual-nodes/92396/32 "2024-10-15T09:08:24Z")

</div>

That's not possible.

Unfortunately the tcp in has no input port therefore it can't be sent an msg to stop. So it would seem a custom tcp in node that takes "control messages" to start and stop it would be what you're looking for.

Far simpler to implement than a "dynamic disable node" feature!

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [15 October 2024 09:18 UTC](https://discourse.nodered.org/t/dynamically-disable-individual-nodes/92396/33 "2024-10-15T09:18:31Z")

</div>

Another way you could do it is with `flow context` and `switch` nodes.

You set a `flow context` from one value to another and that would change how the message goes through the `switch` node.

Basic flow:

```auto
[{"id":"ada8918a8229e0a4","type":"inject","z":"0918ee609bf69fc7","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":true,"onceDelay":0.1,"topic":"","payload":"A","payloadType":"str","x":210,"y":4130,"wires":[["8cd0894a22cf4a28"]]},{"id":"3cc28e0b370e79ee","type":"inject","z":"0918ee609bf69fc7","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"B","payloadType":"str","x":210,"y":4170,"wires":[["8cd0894a22cf4a28"]]},{"id":"8cd0894a22cf4a28","type":"change","z":"0918ee609bf69fc7","name":"","rules":[{"t":"set","p":"condition1","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":390,"y":4150,"wires":[[]]},{"id":"faadf22acfa69730","type":"inject","z":"0918ee609bf69fc7","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"This is a message","payloadType":"str","x":200,"y":4260,"wires":[["0f640bd0ea104d41"]]},{"id":"0f640bd0ea104d41","type":"switch","z":"0918ee609bf69fc7","name":"","property":"condition1","propertyType":"flow","rules":[{"t":"eq","v":"A","vt":"str"},{"t":"eq","v":"B","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":380,"y":4260,"wires":[["69dc21f4e3746808"],["b8eba76d471ec67e"]]},{"id":"69dc21f4e3746808","type":"debug","z":"0918ee609bf69fc7","name":"A","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":540,"y":4210,"wires":[]},{"id":"b8eba76d471ec67e","type":"debug","z":"0918ee609bf69fc7","name":"B","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":540,"y":4290,"wires":[]}]

```

Then you see how the message goes to different places.

---

<div class="post-metadata">

**Author:** ![gregorius](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gregorius/32/73816_2.png) [@gregorius](https://discourse.nodered.org/u/gregorius)\
**Post date:** [15 October 2024 10:15 UTC](https://discourse.nodered.org/t/dynamically-disable-individual-nodes/92396/34 "2024-10-15T10:15:47Z")

</div>

> [@gregorius](#):
>
> Unfortunately the tcp in has no input port therefore it can't be sent an msg to stop.

I was just playing around with a custom node that actually closes all tcp in nodes. It's a hack and not something to be proud of but it does shutdown the tcp in node:

```auto
node.on("input", function (msg, send, done) {
  try {
    RED.nodes.eachNode(nde => {
      if (nde.type == "tcp in") {
        RED.nodes.getNode(nde.id).close()
      }
    })

    send(msg);
    done();
  } catch (err) {
    console.error(err)
    node.error("error occurred", { ...msg, error: err })
    done();
  }
})

```

Obviously this isn't nice thing to be doing since a third-party node is affecting a non-related node. This can't be done in a function node because access to `RED.nodes.eachNode` is not possible via function node.

---

<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:** [14 December 2024 10:16 UTC](https://discourse.nodered.org/t/dynamically-disable-individual-nodes/92396/35 "2024-12-14T10:16:29Z")

</div>

Closed on 14 December 2024 10:16 UTC

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

[Previous page](https://discourse.nodered.org/t/dynamically-disable-individual-nodes/92396.md?page=1)
