Node-red : switch - strange behaviour

OS: Windows 11

Dashboard version: 2.2.0

All my nodes are to the latest version.

Browser: Chrome


I am not sure if this strange behaviour happened after a node-red update.

I am using the switch node ( not from the dashboard) for routing messages. If the msg.payload is true or false, it will take action accordingly.

When the switch evaluates the value, it behaves as a loop. What I mean, it will do the same action several times and then will behave normally, in this case, waiting for the user's selection (ok or no)

Per example. This flow from the print screen.

  1. Message popup and wait for user selection.
  2. if Ok, it will popup a second message to get user confirmation
  3. Then if click OK, data will be deleted in MYSQL db.

The behaviour:

It can loop several times on the first or second popup message and then stop and wait for the user for selection (ok or no) . Then if it is ok, it will delete the information in MySQL DB.

This will happen also in other switches I am using for other tasks as well ( as selection an action if the payload =1 or 2 and so on ..

My Workaround

  1. I replace the switch node by function node and I do a switch(msg.payload) in the code and all works nice
  2. Or I delete the switch node, drop a new one, put back the parameters and then it works normally.

I don't know if anyone got this in the past



Make sure the switch node is checking for the correct type of 1 and 2.

Put a debug node just before the switch node and look for the messages.

If you see the 1 and 2 as BLUE, they are numbers. If they are RED, they are `text.

So in the switch node make sure you have the correct type selected.

Do you mean that node red is version 2.2.0? You can check this at the bottom of the menu dropdown. You said this happened after a node-red update, but the latest node-red is 2.2.2, though looking at the release notes I don't see anything there that would cause the problem. It might be worth updating anyway.

Current node-red-dashboard latest is 3.1.6

Assuming it is still failing after the update, get it into the failing mode, mark all those nodes Use Ctrl-E to export to the clipboard and paste it here, using the </> button at the top of the forum entry window when pasting it in. Then we can import it, have a look at the settings and test it.

Hi ,
I should put the information as well. I used the debug nodes as well as the flow debugger.
It is good you are taking about the numbrs or text type, I did the mistake in the past.

When I use the flow debugger, it shows, in the blue debugger info break point the amount of times it will loop - yesterday It went up to 36 !! it loop the Message Popup Windows 36 times and then wait for that I answer the question ( OK or No) . The day before, without changing anything, it was working just fine..
As I mentioned, if I delete the switch node and drop a new one and put inside exactly the same condition it is working .. It was doing that this morning and that is what I did and now works just fine.

thanks for the reply,


I would nearly suggest you post the code, but as they are foreign nodes, it won't be easy for most people to load it.

Can you make a smaller flow with an inject node and the switch node.
(Actually a couple of inject nodes. One that you want to detect and one that won't be detected. Maybe 2 not to be detected just to be sure)

See if that works. It may help you get a better picture of what is going on.

Sorry, just spit balling ideas.

It is ok and normal, debug process is not always easy. I have an idea, I will take print screen of each action and put the code bellow the print screen in the order they are call.. will see if it is good...

Then it will be easy to follow and might find what could be wrong..

I had not realised that you were using non-standard nodes. Tell us what they are and show us what is coming out of those nodes when it is failing. Also how you have configured the switch nodes.

If you configure the debug nodes to ouput to the console then they output to the node red log so you can analyse them later. Give the nodes names.

Here it comes the process


1**. Depending the action, a message number is assign to msg.message**

Here what inside Transaction validation node
Transaction validation used the MYSQL transaction status

Then dependig if 0 or 1 the appropriated message for the Popup Windows

Number asociated to the message.

2. Link to the message center.
Message center is a sub flow who handle and assing the appropriate message according to the Integer assigned to msg.message


Popup Messages NODE

When message arrive to message center, it is process by the sub node Popup Message

Message flow in the sub node

Switch handle message number and route it to the selected number

The appropriate text is assign from a Global variable according to the selected default language.

The HTML code to display the message, Icon and message Header

Action Message Node
STD message config.


Then it return to the calling Tab with the selected user's value



Switch node
Validate if true or false

this part will only happen if the action required a second validation as Delete Data
Message 8 - Delete Confirmation
This morning it was looping here (up to 36 times)

Return to Sub Flow to get the same actions as the one describe prior with the same configuration

Cleaning any left msg.payload

Answer Validation

Then it links to the next action ( in this case a SQL delete )

I fixed it this morning by deleting change node ( i just realized, this time it wasn;t switch node that I deleted but the change node) and recreated it .

What I'll do next, I will try to reproduce the bug and getting the console log to see what I will get.


Often symptoms like you describe are caused by timing issues. Have you considered what would happen if several messages arrive at the front end very close together?

Are you using flow or global context at all?

Answering my own question I see you are using flow.action. So if two messages arrive close together how are you keeping the flow.action setting separate for the two messages that will be in the flow at the same time?

In fact - for flow.action is attached to Multistate switch. The action is either Add - Add - Delete. - I clean each time the status change and if any save is done, the value is reset to default mode ( edit)


So have you considered what happens if two messages arrive at the front at almost the same time? There isn't anything in your flow, as far as I can see, to stop them both being actioned in parallel. Will your flow work in that case?

That is a good point. I didn't look closely at it

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