On Start called multiple times

When using "On Start" code of a Function node in a subflow, the code is called multiple times. This is unexpected, at least by me. Is there any way to suppress/configure this?

Example output:

9 Mar 16:54:36 - [info] Started flows
9 Mar 16:54:36 - [info] [function:833ae1fa0bc8173e] On Start
9 Mar 16:54:36 - [info] [function:9bb3532e2df19fe8] On Start

Example flows.json:

[
    {
        "id": "719bc69b20978590",
        "type": "tab",
        "label": "Flow 1",
        "disabled": false,
        "info": "",
        "env": []
    },
    {
        "id": "93c9faba1011712c",
        "type": "subflow",
        "name": "Subflow 1",
        "info": "",
        "in": [
            {
                "x": 60,
                "y": 40,
                "wires": [
                    {
                        "id": "15348321803f2de8"
                    }
                ]
            }
        ],
        "out": [
            {
                "x": 340,
                "y": 40,
                "wires": [
                    {
                        "id": "15348321803f2de8",
                        "port": 0
                    }
                ]
            }
        ]
    },
    {
        "id": "15348321803f2de8",
        "type": "function",
        "z": "93c9faba1011712c",
        "name": "",
        "func": "\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "// Code added here will be run once\n// whenever the node is started.\nnode.log('On Start');",
        "finalize": "",
        "libs": [],
        "x": 200,
        "y": 40,
        "wires": [
            []
        ]
    },
    {
        "id": "fa74d793acb7fb35",
        "type": "inject",
        "z": "719bc69b20978590",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "x": 160,
        "y": 60,
        "wires": [
            [
                "9747212c8784f910"
            ]
        ]
    },
    {
        "id": "85f5417e36908743",
        "type": "debug",
        "z": "719bc69b20978590",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 370,
        "y": 240,
        "wires": []
    },
    {
        "id": "9747212c8784f910",
        "type": "subflow:93c9faba1011712c",
        "z": "719bc69b20978590",
        "name": "",
        "x": 240,
        "y": 120,
        "wires": [
            [
                "cbbc22d504807358"
            ]
        ]
    },
    {
        "id": "cbbc22d504807358",
        "type": "subflow:93c9faba1011712c",
        "z": "719bc69b20978590",
        "name": "",
        "x": 300,
        "y": 180,
        "wires": [
            [
                "85f5417e36908743"
            ]
        ]
    }
]

Because every instance of a subflow is its own entities. When you have 2 subflow instances in your flows, you have 2x everything inside the subflow template.

If you find this unexpected, then you are either using subflows wrongly or you need to use LINK CALL node.

Looking at your code, it looks like you want to create "utility functions" (or subroutines) - thats what the Link Call is for.

If a "LINK CALL" is a utility function/subrouting, what is a subflow good for? What are the benefits there?

The Subflow allows you to specify parameters for that particular instance.
Also you can use flow context within it, where the context is different for each subflow instance.

Also a subflow can have multiple outputs and Status.

Subflows do not have a timeout. Is it possible to increase the LINK CALL timeout to infinite?

No, but if you are not interested in the timeout use a catch node (pointed at the link call) to catch the error.

The question for me is, why are you getting timeouts?

The subflows are to complex to sort out all possible reasons for a timeout.

  • What is the maximum timeout value possible? Is it possible to disable the timeout?
  • What is the solution for Node-RED 1.3.7? There is no Link-Call available, yet.

I expect it is possible to set it to many hours, have you tried? How big do you need to set it?

Upgrade to current version.

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