node-red / node-red-nodes

Extra nodes for Node-RED
Other
986 stars 591 forks source link

Daemon node #660

Open 26tajeen opened 4 years ago

26tajeen commented 4 years ago

Daemon Node

The daemon node does not perform as reliably and accurately as the exec node. See here and here

dceejay commented 4 years ago

So what are these "unwanted changes" you mention ? How did you have the exec node configured ? in exec or spawn mode ? What is not reliable ? Does it crash ? stall ? What is not accurate ? It just passes on the the data your script gives it so... maybe that is not accurate ?

colinl commented 4 years ago

In the node-red thread I thought you said you had used debug nodes to document a case where a Switch node was not performing as expected (when fed from a daemon node). In which case it is a problem with the Switch node not the daemon node.

26tajeen commented 4 years ago

In which case it is a problem with the Switch node not the daemon node.

I don't follow this logic - the entire flow was identical apart from the exec or daemon node were swapped around. When swapped back to the exec node it worked reliably.

colinl commented 4 years ago

You keep saying that, but unless you add the debug nodes, trap a failing situation, and fully analyse it to work out which node is not behaving as you expect then there is nothing to go on. Either the exec node is returning something it shouldn't (or not returning something it should) or one of the other nodes is misbehaving. Unless you can tie it down it is impossible to investigate.

knolleary commented 4 years ago

Of the two threads linked to, the more relevant one is this one: https://discourse.nodered.org/t/move-from-exec-node-to-daemon-node-has-caused-an-unusual-problem/28566

This thread describes the actual issue in swapping the Exec node for the Daemon node. From that thread, @lancelon shared this Debug output:

Move_from_exec_node_to_daemon_node_has_caused_an_unusual_problem_-_General_-_Node-RED_Forum

The main takeaway is the last entry - compared to the other entries, you can see it contains two lines of std out from the process and not just one.

So the question is whether there is a difference between the Exec and Daemon nodes' handling of stdout - and how the output is split into individual messages.

If both nodes just pass on output as and when they receive it from the child process, then the question is why does the daemon's child process sometimes return more than the exec node's child process.

26tajeen commented 4 years ago

Thanks. @knolleary has put it better than I could have. Another thing is exec and daemon nodes seem to handle carriage returns differently. I know I "keep saying it" but the Daemon node was unreliable and the exec node was reliable with the exact same flow. So I don't think it's the child process that's at fault because it was consistently consistent with the exec node. I'm OK now because I've moved over to the AMI connector node but I just thought it might be worth flagging this up here so it was raised somewhere. Sorry if that was the wrong thing to do. My head is a bit scrambled at the moment.

dceejay commented 4 years ago

not a problem to log it here. I'm just trying to understand how you had them configured exactly (well the exec node - as that has two different modes (and the daemon node doesn't) ) - The spawn mode of exec does return one line at a time and the exec mode waits for all it's output. However even in both modes they rely on how stdout gets flushed from your app... for example python has an optional -u parameter to make sure the output is unbuffered and comes out directly, without that flag python will batch up lines until it decides to send them. I have no idea if php has a flush option for output... it probably does somehow.

So assuming you had the exec in spawn mode...??? then the daemon node also uses spawn mode - but does handle the output slightly differently. The exec node automatically tests the output to see if it is utf8 (string) and if so assumes it's a string and sends a string - whereas the daemon node you get to select what format you want. And it has two string like options - image one to return a string (so the same (in theory) as the exec node - and another to return multiple lines - which actually splits lines on the \n character - so in fact maybe that option would "fix" it for you - unless there is some other wrinkle we don't yet know about.

Glad you've got it working with the AMI node - but any clues you can share here would be appreciated.