Dynamically Disable individual nodes

From time to time there comes a need to disable individual nodes.
At the moment I'm storing those nodes into separate flow and disable it which looks odd (but it works)

Is there any plans to implement this functionality or is it not possible because of some restrictions?

My use case is to simulate TCP/IP nodes connection drop
image

image

This has already been possible for a long time. :slightly_smiling_face:

You can easily disable/enable selected nodes via the context menu. Right click on a node, then "Node" --> "Disable selected nodes".

Tip: I'm using that feature regularly, so I added custom keyboard shortcuts (crtl-shift-d and crtl-shift-e) for that.

Thanks, that is clear. I changed topic name, my request is to be able to do it dynamically.

Same as described in here:

Changed topic name

Ah, you mean disabling them via message.

The "disable" flag is stored in the flow, it's no a runtime feature. So I don't think it is currently possible without modifying and redeploying, either using the editor or the admin endpoints.

That would be something for the core devs to consider.

If you want your connection to end in nirvana (i.e. get no response) why not use a switch node that x% of the time hits a disabled node?

Something like this flow:

[{"id":"800d74d9379d0299","type":"inject","z":"19b2bc07fbb4a423","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":522,"y":581,"wires":[["5dd0c0a13bc3c674"]]},{"id":"5dd0c0a13bc3c674","type":"switch","z":"19b2bc07fbb4a423","name":"","property":"$random()","propertyType":"jsonata","rules":[{"t":"gt","v":"0.5","vt":"num"},{"t":"else"}],"checkall":"false","repair":false,"outputs":2,"x":717,"y":602,"wires":[["86ef039c237c1e66"],["f92464f9cfbb3c8f"]]},{"id":"86ef039c237c1e66","type":"debug","z":"19b2bc07fbb4a423","name":"debug 306","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":909,"y":528,"wires":[]},{"id":"f92464f9cfbb3c8f","type":"debug","z":"19b2bc07fbb4a423","d":true,"name":"debug 307","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":919,"y":642,"wires":[]}]

You could also add a global variable to that switch so that you toggle it or add to toggle to a dashboard to switch or a number of other things to make this dynamic (i.e. without having to do a redeploy).

Do you specifically mean config nodes?

In what regard?

You can disable any node in the editor, even config nodes. Sometimes I use that "feature" to manually reset a config node during the development of custom nodes (e.g. to force reestablishing connections).

However, the custom keyboard shortcuts I set up only work for nodes on the canvas.

If you just temporarily want to stop the flow of message you could use contrib simple gate node.

1 Like

You can do this by editing the node properties and then deploying the flow(s).
Works only from the editor

The solutions suggested, using a Switch node or similar to stop messages flowing do not work for config nodes. As far as I know there is no way to disable a config node dynamically.

I don't want to stop a flow of messages.

In reality NR is communicating with PLC via TCP request.
I want to create test scenarios, which simulate TCP connection drop when PLC TCP side is misconfigured and drops connection.

Best representation of that I found is to create a temp listener like TCP-out node. Then connection is established
image
tcp request node change status - I pick it up and do following actions

when I disable tcp-out node, tcp-request node changes status once again
image

I pick this status and do further actions.

since you are one of core devs I wanted to ask if it is fundamentally possible to do it and can it be implemented further nodered versions (NR v5 etc), or is it just not possible and only work around is to disable whole flow?

This request is popping up every year or so

have you tried setting up a switch node? And why does it not work with a switch node?

It's the connection he wants to cut, not the message. As long as the node is active, the connection is also active.

I am a contributor but I am not part of the team :sweat_smile:

Exactly! I've noticed that trying to automate testing is quite a separate challenge (but that's a separate topic)

So literally deactivating the node via disabling it and then redeploying the flow is the only way to achieve that? - Not being cynical here, literally surprised to think that!

EDIT: weird really, I was thinking this morning that I would like to have a HTTP response node that just drops the connection without sending out a reply - I couldn't think of a way to do that but it wasn't important either :wink:

Either you create a custom node that does it by itself with a timeout (or button in editor).

Yes, I don't see any other possibility.

Still you know core better than 99% of users. Maybe somebody from the core will provide insights.

What about a function node? The connection - at least in the case of a HTTP in node - is transported with the message, so it would be possible, in a function node, to close that connection.

The HTTP out node uses the msg.res._res to close the original connection made when the client connects to the http in node.

So if I created a function node that does this msg.res._res.socket.destroy() I might be able to drop the line.

Don't forget that you can use the library feature of the export/import dialog for this.

To really drop/close the connection, I see only two options:

  • disable the config node
    • only manually at this time (edit/deploy)
  • add support for control messages to the TCP core nodes (like mqtt and some other nodes have implemented it)