Could anyone try out a flow on Node-RED a v3.1.x and / or V4.x version?
Please let me know your setup (OS (Win/Mac/Linux/Docker), Node-RED version, NodeJS version - they may be relevant)
TL;DR;
I am working on some code in core and want to be sure I respect the way a function times out but I cannot get it to do anything in the versions I have available to me at the moment. For me, in NR4.0.9/Node20, NR4.15/Node22 and even NR5.beta-2/Node22, I never get an error and the function continues regardless of the timeout.
Demo setup
- first flow
- function code awaits a 2 sec promise
- warns "after awaiting 2 second sleep"
- returns the msg
- second flow
- function code sets up a 2s
setTimeout - after setTimeout resolves:
- warns "after awaiting 2 second sleep"
- sends msg
- function code sets up a 2s
NOTE: both function nodes have a timeout setting of 1
At no time, did an error get thrown/caught
From the docs:
Handling a Timeout
Since Node-RED 3.1.0
It is possible to set a timeout for the function node on the Setup tab. This value, in seconds, is how long the runtime will allow the Function node to run for before raising an error. If set to 0, the default, no timeout is applied.
Flow to try out:
[{"id":"496cebb58846c847","type":"function","z":"d1c96cf8529a5579","name":"code awaits 2s sleep, function timeout setting is 1s","func":"await new Promise(r => setTimeout(r, 2000));\nnode.warn('after awaiting 2 second sleep')\nreturn msg\n","outputs":1,"timeout":"1","noerr":0,"initialize":"","finalize":"","libs":[],"x":810,"y":320,"wires":[["a80c0cdd911b28c6"]]},{"id":"52fa1c38a816ca85","type":"inject","z":"d1c96cf8529a5579","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"true","payloadType":"bool","x":530,"y":320,"wires":[["496cebb58846c847"]]},{"id":"a80c0cdd911b28c6","type":"debug","z":"d1c96cf8529a5579","name":"await sleep version","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1210,"y":320,"wires":[]},{"id":"8e6f2e764efd5607","type":"complete","z":"d1c96cf8529a5579","name":"","scope":["496cebb58846c847","b94941589bf06811"],"uncaught":false,"x":990,"y":420,"wires":[["8629dcf10b4fc6c5"]]},{"id":"8629dcf10b4fc6c5","type":"debug","z":"d1c96cf8529a5579","name":"complete","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"true","targetType":"full","statusVal":"","statusType":"counter","x":1180,"y":420,"wires":[]},{"id":"b94941589bf06811","type":"function","z":"d1c96cf8529a5579","name":"code sends after setTimeout 2s, function timeout setting is 1s","func":"setTimeout(function() {\n node.warn('setTimeout elapsed its 2 seconds setting')\n node.send(msg)\n}, 2000);\n\n","outputs":1,"timeout":"1","noerr":0,"initialize":"","finalize":"","libs":[],"x":840,"y":360,"wires":[["088e25f9ab8944ec"]]},{"id":"f3c7e4089915cb27","type":"inject","z":"d1c96cf8529a5579","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"true","payloadType":"bool","x":530,"y":360,"wires":[["b94941589bf06811"]]},{"id":"088e25f9ab8944ec","type":"debug","z":"d1c96cf8529a5579","name":"setTimeout version","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1210,"y":360,"wires":[]},{"id":"747764c2367e43a4","type":"catch","z":"d1c96cf8529a5579","name":"","scope":["496cebb58846c847","b94941589bf06811"],"uncaught":false,"x":1010,"y":480,"wires":[["01d08d2a641105c4"]]},{"id":"01d08d2a641105c4","type":"debug","z":"d1c96cf8529a5579","name":"caught","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"true","targetType":"full","statusVal":"","statusType":"counter","x":1170.895751953125,"y":478.90277099609375,"wires":[]}]
Did something change and the docs are out of date?
Am i missing something obvious?


