Msg.reset inside subflow not working on delay

I'm building an AV control system using node-red. One of my actions is for listening to music at night. In that action it sets a delay for 90 minutes to turn everything off. That works 100% correctly. In the other actions I send a msg to the night music subflow with msg.reset=true to cancel the delay. This is in case the night music was accidentally hit so you can hit the other action and have it cancel the delay so it doesn't shut everything off in 90 minutes. This msg.reset=true fails to cancel the delay 100% of the time.

To test it I created a subflow that prints the entire msg then has a delay for 2 minutes then displays the entire msg via the debug node. I have two injects in a flow to test it, one sends a msg to the subflow, the other sends a msg with msg.reset=true set. These work 100% of the time, hit the first one and you see the msg displayed and the delay is activated. 2 minutes later you see the entire msg displayed again. If you press the first inject then after that press the second inject you see the debug msg displayed from the first inject then the msg displayed with reset=true from the second inject but you don't see the msg displayed again from the debug node after the delay node. This works 100% of the time.

However, if I move the setting of the msg.reset into a subflow that will call the original test subflow that will fail 100% of the time even though the debug message shows msg.reset is set to true. It will always execute the debug node after the delay node. In other words, the start delay inject calls subflow A which is the one that has the delay. The cancel inject calls subflow B which uses a change node to set msg.reset=true then pass the msg to subflow A. You see the msg.reset=true in the debug log but the debug node after the delay is always executed thus it didn't cancel the delay.

Any ideas why the reset does not work correctly when initiated from within a subflow but does work correctly when initiated from within a flow?

Hi. Can you provide a minimal sample flow that demonstrates this?

As a new user it will not let me upload the exported flows.

Hi @rpoole

You shouldn't need to attach the flow as a file - just include the JSON contents between 2 rows of 3 backticks

```
JSON / File contents 
```

Cancel Delay Test flow
...
[
{
"id": "5000652e2e0639f2",
"type": "subflow",
"name": "Cancel Delay Failure",
"info": "",
"category": "",
"in": [
{
"x": 180,
"y": 140,
"wires": [
{
"id": "93e904b826c5b927"
}
]
}
],
"out": ,
"env": ,
"meta": {},
"color": "#DDAA99"
},
{
"id": "ca1fc825888ca8ad",
"type": "subflow:93d1b74d61d4f90f",
"z": "5000652e2e0639f2",
"name": "",
"x": 520,
"y": 140,
"wires":
},
{
"id": "93e904b826c5b927",
"type": "change",
"z": "5000652e2e0639f2",
"name": "",
"rules": [
{
"t": "set",
"p": "reset",
"pt": "msg",
"to": "true",
"tot": "bool"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 320,
"y": 140,
"wires": [
[
"ca1fc825888ca8ad"
]
]
},
{
"id": "93d1b74d61d4f90f",
"type": "subflow",
"name": "TestMsgCancel",
"info": "",
"category": "",
"in": [
{
"x": 80,
"y": 100,
"wires": [
{
"id": "8e95cef841af3afe"
},
{
"id": "1b3f56701316f785"
}
]
}
],
"out": ,
"env": ,
"meta": {},
"color": "#DDAA99"
},
{
"id": "8e95cef841af3afe",
"type": "delay",
"z": "93d1b74d61d4f90f",
"name": "",
"pauseType": "delay",
"timeout": "5",
"timeoutUnits": "seconds",
"rate": "1",
"nbRateUnits": "1",
"rateUnits": "second",
"randomFirst": "1",
"randomLast": "5",
"randomUnits": "seconds",
"drop": false,
"allowrate": false,
"outputs": 1,
"x": 280,
"y": 100,
"wires": [
[
"f8bc75fb8ecb0338"
]
]
},
{
"id": "f8bc75fb8ecb0338",
"type": "debug",
"z": "93d1b74d61d4f90f",
"name": "",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": ""delay finished"",
"targetType": "jsonata",
"statusVal": "",
"statusType": "auto",
"x": 480,
"y": 100,
"wires":
},
{
"id": "1b3f56701316f785",
"type": "debug",
"z": "93d1b74d61d4f90f",
"name": "",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"statusVal": "",
"statusType": "auto",
"x": 270,
"y": 40,
"wires":
},
{
"id": "aa2a0675de682cbc",
"type": "tab",
"label": "Cancel Delay Test",
"disabled": false,
"info": "",
"env":
},
{
"id": "e8c53ad359599fe8",
"type": "inject",
"z": "aa2a0675de682cbc",
"name": "Set Delay",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "",
"payloadType": "date",
"x": 120,
"y": 140,
"wires": [
[
"d04e986cf42f4425"
]
]
},
{
"id": "77bd611303adafee",
"type": "inject",
"z": "aa2a0675de682cbc",
"name": "Cancel Delay",
"props": [
{
"p": "reset",
"v": "true",
"vt": "bool"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"x": 130,
"y": 180,
"wires": [
[
"d04e986cf42f4425"
]
]
},
{
"id": "d04e986cf42f4425",
"type": "subflow:93d1b74d61d4f90f",
"z": "aa2a0675de682cbc",
"name": "",
"x": 340,
"y": 140,
"wires":
},
{
"id": "3433a4566b875615",
"type": "comment",
"z": "aa2a0675de682cbc",
"name": "This works",
"info": "This works setting msg.reset=true from within a flow",
"x": 80,
"y": 80,
"wires":
},
{
"id": "1c1812546a3e8f75",
"type": "inject",
"z": "aa2a0675de682cbc",
"name": "Cancel Delay",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "",
"payloadType": "date",
"x": 130,
"y": 320,
"wires": [
[
"e66ae0ac72899773"
]
]
},
{
"id": "78ab1eb439ec1abc",
"type": "comment",
"z": "aa2a0675de682cbc",
"name": "This fails",
"info": "This fails setting msg.reset=true from within a subflow",
"x": 80,
"y": 260,
"wires":
},
{
"id": "e66ae0ac72899773",
"type": "subflow:5000652e2e0639f2",
"z": "aa2a0675de682cbc",
"name": "",
"x": 350,
"y": 320,
"wires":
}
]
...

Test Msg Cancel flow
...
[
{
"id": "5000652e2e0639f2",
"type": "subflow",
"name": "Cancel Delay Failure",
"info": "",
"category": "",
"in": [
{
"x": 180,
"y": 140,
"wires": [
{
"id": "93e904b826c5b927"
}
]
}
],
"out": ,
"env": ,
"meta": {},
"color": "#DDAA99"
},
{
"id": "ca1fc825888ca8ad",
"type": "subflow:93d1b74d61d4f90f",
"z": "5000652e2e0639f2",
"name": "",
"x": 520,
"y": 140,
"wires":
},
{
"id": "93e904b826c5b927",
"type": "change",
"z": "5000652e2e0639f2",
"name": "",
"rules": [
{
"t": "set",
"p": "reset",
"pt": "msg",
"to": "true",
"tot": "bool"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 320,
"y": 140,
"wires": [
[
"ca1fc825888ca8ad"
]
]
},
{
"id": "93d1b74d61d4f90f",
"type": "subflow",
"name": "TestMsgCancel",
"info": "",
"category": "",
"in": [
{
"x": 80,
"y": 100,
"wires": [
{
"id": "8e95cef841af3afe"
},
{
"id": "1b3f56701316f785"
}
]
}
],
"out": ,
"env": ,
"meta": {},
"color": "#DDAA99"
},
{
"id": "8e95cef841af3afe",
"type": "delay",
"z": "93d1b74d61d4f90f",
"name": "",
"pauseType": "delay",
"timeout": "5",
"timeoutUnits": "seconds",
"rate": "1",
"nbRateUnits": "1",
"rateUnits": "second",
"randomFirst": "1",
"randomLast": "5",
"randomUnits": "seconds",
"drop": false,
"allowrate": false,
"outputs": 1,
"x": 280,
"y": 100,
"wires": [
[
"f8bc75fb8ecb0338"
]
]
},
{
"id": "f8bc75fb8ecb0338",
"type": "debug",
"z": "93d1b74d61d4f90f",
"name": "",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": ""delay finished"",
"targetType": "jsonata",
"statusVal": "",
"statusType": "auto",
"x": 480,
"y": 100,
"wires":
},
{
"id": "1b3f56701316f785",
"type": "debug",
"z": "93d1b74d61d4f90f",
"name": "",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"statusVal": "",
"statusType": "auto",
"x": 270,
"y": 40,
"wires":
},
{
"id": "aa2a0675de682cbc",
"type": "tab",
"label": "Cancel Delay Works",
"disabled": false,
"info": "",
"env":
},
{
"id": "e8c53ad359599fe8",
"type": "inject",
"z": "aa2a0675de682cbc",
"name": "Set Delay",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "",
"payloadType": "date",
"x": 120,
"y": 140,
"wires": [
[
"d04e986cf42f4425"
]
]
},
{
"id": "77bd611303adafee",
"type": "inject",
"z": "aa2a0675de682cbc",
"name": "Cancel Delay",
"props": [
{
"p": "reset",
"v": "true",
"vt": "bool"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"x": 130,
"y": 180,
"wires": [
[
"d04e986cf42f4425"
]
]
},
{
"id": "d04e986cf42f4425",
"type": "subflow:93d1b74d61d4f90f",
"z": "aa2a0675de682cbc",
"name": "",
"x": 340,
"y": 140,
"wires":
},
{
"id": "3433a4566b875615",
"type": "comment",
"z": "aa2a0675de682cbc",
"name": "This works",
"info": "This works setting msg.reset=true from within a flow",
"x": 80,
"y": 80,
"wires":
},
{
"id": "1c1812546a3e8f75",
"type": "inject",
"z": "aa2a0675de682cbc",
"name": "Cancel Delay",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "",
"payloadType": "date",
"x": 130,
"y": 320,
"wires": [
[
"e66ae0ac72899773"
]
]
},
{
"id": "78ab1eb439ec1abc",
"type": "comment",
"z": "aa2a0675de682cbc",
"name": "This fails",
"info": "This fails setting msg.reset=true from within a subflow",
"x": 80,
"y": 260,
"wires":
},
{
"id": "e66ae0ac72899773",
"type": "subflow:5000652e2e0639f2",
"z": "aa2a0675de682cbc",
"name": "",
"x": 350,
"y": 320,
"wires":
}
]
...

Cancel Delay Failure flow

[
    {
        "id": "5000652e2e0639f2",
        "type": "subflow",
        "name": "Cancel Delay Failure",
        "info": "",
        "category": "",
        "in": [
            {
                "x": 180,
                "y": 140,
                "wires": [
                    {
                        "id": "93e904b826c5b927"
                    }
                ]
            }
        ],
        "out": [],
        "env": [],
        "meta": {},
        "color": "#DDAA99"
    },
    {
        "id": "ca1fc825888ca8ad",
        "type": "subflow:93d1b74d61d4f90f",
        "z": "5000652e2e0639f2",
        "name": "",
        "x": 520,
        "y": 140,
        "wires": []
    },
    {
        "id": "93e904b826c5b927",
        "type": "change",
        "z": "5000652e2e0639f2",
        "name": "",
        "rules": [
            {
                "t": "set",
                "p": "reset",
                "pt": "msg",
                "to": "true",
                "tot": "bool"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 320,
        "y": 140,
        "wires": [
            [
                "ca1fc825888ca8ad"
            ]
        ]
    },
    {
        "id": "93d1b74d61d4f90f",
        "type": "subflow",
        "name": "TestMsgCancel",
        "info": "",
        "category": "",
        "in": [
            {
                "x": 80,
                "y": 100,
                "wires": [
                    {
                        "id": "8e95cef841af3afe"
                    },
                    {
                        "id": "1b3f56701316f785"
                    }
                ]
            }
        ],
        "out": [],
        "env": [],
        "meta": {},
        "color": "#DDAA99"
    },
    {
        "id": "8e95cef841af3afe",
        "type": "delay",
        "z": "93d1b74d61d4f90f",
        "name": "",
        "pauseType": "delay",
        "timeout": "5",
        "timeoutUnits": "seconds",
        "rate": "1",
        "nbRateUnits": "1",
        "rateUnits": "second",
        "randomFirst": "1",
        "randomLast": "5",
        "randomUnits": "seconds",
        "drop": false,
        "allowrate": false,
        "outputs": 1,
        "x": 280,
        "y": 100,
        "wires": [
            [
                "f8bc75fb8ecb0338"
            ]
        ]
    },
    {
        "id": "f8bc75fb8ecb0338",
        "type": "debug",
        "z": "93d1b74d61d4f90f",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "\"delay finished\"",
        "targetType": "jsonata",
        "statusVal": "",
        "statusType": "auto",
        "x": 480,
        "y": 100,
        "wires": []
    },
    {
        "id": "1b3f56701316f785",
        "type": "debug",
        "z": "93d1b74d61d4f90f",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 270,
        "y": 40,
        "wires": []
    },
    {
        "id": "aa2a0675de682cbc",
        "type": "tab",
        "label": "Cancel Delay Works",
        "disabled": false,
        "info": "",
        "env": []
    },
    {
        "id": "e8c53ad359599fe8",
        "type": "inject",
        "z": "aa2a0675de682cbc",
        "name": "Set Delay",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "x": 120,
        "y": 140,
        "wires": [
            [
                "d04e986cf42f4425"
            ]
        ]
    },
    {
        "id": "77bd611303adafee",
        "type": "inject",
        "z": "aa2a0675de682cbc",
        "name": "Cancel Delay",
        "props": [
            {
                "p": "reset",
                "v": "true",
                "vt": "bool"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "x": 130,
        "y": 180,
        "wires": [
            [
                "d04e986cf42f4425"
            ]
        ]
    },
    {
        "id": "d04e986cf42f4425",
        "type": "subflow:93d1b74d61d4f90f",
        "z": "aa2a0675de682cbc",
        "name": "",
        "x": 340,
        "y": 140,
        "wires": []
    },
    {
        "id": "3433a4566b875615",
        "type": "comment",
        "z": "aa2a0675de682cbc",
        "name": "This works",
        "info": "This works setting msg.reset=true from within a flow",
        "x": 80,
        "y": 80,
        "wires": []
    },
    {
        "id": "1c1812546a3e8f75",
        "type": "inject",
        "z": "aa2a0675de682cbc",
        "name": "Cancel Delay",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "x": 130,
        "y": 320,
        "wires": [
            [
                "e66ae0ac72899773"
            ]
        ]
    },
    {
        "id": "78ab1eb439ec1abc",
        "type": "comment",
        "z": "aa2a0675de682cbc",
        "name": "This fails",
        "info": "This fails setting msg.reset=true from within a subflow",
        "x": 80,
        "y": 260,
        "wires": []
    },
    {
        "id": "e66ae0ac72899773",
        "type": "subflow:5000652e2e0639f2",
        "z": "aa2a0675de682cbc",
        "name": "",
        "x": 350,
        "y": 320,
        "wires": []
    }
]

In order to make code readable and usable it is necessary to surround your code with three backticks (also known as a left quote or backquote ```)

``` 
   code goes here 
```

You can edit and correct your post by clicking the pencil :pencil2: icon.

See this post for more details - https://discourse.nodered.org/t/how-to-share-code-or-flow-json/506

Backtick (`) not single quote (') :sweat_smile:

Test Msg Cancel

[
    {
        "id": "5000652e2e0639f2",
        "type": "subflow",
        "name": "Cancel Delay Failure",
        "info": "",
        "category": "",
        "in": [
            {
                "x": 180,
                "y": 140,
                "wires": [
                    {
                        "id": "93e904b826c5b927"
                    }
                ]
            }
        ],
        "out": [],
        "env": [],
        "meta": {},
        "color": "#DDAA99"
    },
    {
        "id": "ca1fc825888ca8ad",
        "type": "subflow:93d1b74d61d4f90f",
        "z": "5000652e2e0639f2",
        "name": "",
        "x": 520,
        "y": 140,
        "wires": []
    },
    {
        "id": "93e904b826c5b927",
        "type": "change",
        "z": "5000652e2e0639f2",
        "name": "",
        "rules": [
            {
                "t": "set",
                "p": "reset",
                "pt": "msg",
                "to": "true",
                "tot": "bool"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 320,
        "y": 140,
        "wires": [
            [
                "ca1fc825888ca8ad"
            ]
        ]
    },
    {
        "id": "93d1b74d61d4f90f",
        "type": "subflow",
        "name": "TestMsgCancel",
        "info": "",
        "category": "",
        "in": [
            {
                "x": 80,
                "y": 100,
                "wires": [
                    {
                        "id": "8e95cef841af3afe"
                    },
                    {
                        "id": "1b3f56701316f785"
                    }
                ]
            }
        ],
        "out": [],
        "env": [],
        "meta": {},
        "color": "#DDAA99"
    },
    {
        "id": "8e95cef841af3afe",
        "type": "delay",
        "z": "93d1b74d61d4f90f",
        "name": "",
        "pauseType": "delay",
        "timeout": "5",
        "timeoutUnits": "seconds",
        "rate": "1",
        "nbRateUnits": "1",
        "rateUnits": "second",
        "randomFirst": "1",
        "randomLast": "5",
        "randomUnits": "seconds",
        "drop": false,
        "allowrate": false,
        "outputs": 1,
        "x": 280,
        "y": 100,
        "wires": [
            [
                "f8bc75fb8ecb0338"
            ]
        ]
    },
    {
        "id": "f8bc75fb8ecb0338",
        "type": "debug",
        "z": "93d1b74d61d4f90f",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "\"delay finished\"",
        "targetType": "jsonata",
        "statusVal": "",
        "statusType": "auto",
        "x": 480,
        "y": 100,
        "wires": []
    },
    {
        "id": "1b3f56701316f785",
        "type": "debug",
        "z": "93d1b74d61d4f90f",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 270,
        "y": 40,
        "wires": []
    },
    {
        "id": "aa2a0675de682cbc",
        "type": "tab",
        "label": "Cancel Delay Works",
        "disabled": false,
        "info": "",
        "env": []
    },
    {
        "id": "e8c53ad359599fe8",
        "type": "inject",
        "z": "aa2a0675de682cbc",
        "name": "Set Delay",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "x": 120,
        "y": 140,
        "wires": [
            [
                "d04e986cf42f4425"
            ]
        ]
    },
    {
        "id": "77bd611303adafee",
        "type": "inject",
        "z": "aa2a0675de682cbc",
        "name": "Cancel Delay",
        "props": [
            {
                "p": "reset",
                "v": "true",
                "vt": "bool"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "x": 130,
        "y": 180,
        "wires": [
            [
                "d04e986cf42f4425"
            ]
        ]
    },
    {
        "id": "d04e986cf42f4425",
        "type": "subflow:93d1b74d61d4f90f",
        "z": "aa2a0675de682cbc",
        "name": "",
        "x": 340,
        "y": 140,
        "wires": []
    },
    {
        "id": "3433a4566b875615",
        "type": "comment",
        "z": "aa2a0675de682cbc",
        "name": "This works",
        "info": "This works setting msg.reset=true from within a flow",
        "x": 80,
        "y": 80,
        "wires": []
    },
    {
        "id": "1c1812546a3e8f75",
        "type": "inject",
        "z": "aa2a0675de682cbc",
        "name": "Cancel Delay",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "x": 130,
        "y": 320,
        "wires": [
            [
                "e66ae0ac72899773"
            ]
        ]
    },
    {
        "id": "78ab1eb439ec1abc",
        "type": "comment",
        "z": "aa2a0675de682cbc",
        "name": "This fails",
        "info": "This fails setting msg.reset=true from within a subflow",
        "x": 80,
        "y": 260,
        "wires": []
    },
    {
        "id": "e66ae0ac72899773",
        "type": "subflow:5000652e2e0639f2",
        "z": "aa2a0675de682cbc",
        "name": "",
        "x": 350,
        "y": 320,
        "wires": []
    }
]

Cancel Delay Failure

[
    {
        "id": "5000652e2e0639f2",
        "type": "subflow",
        "name": "Cancel Delay Failure",
        "info": "",
        "category": "",
        "in": [
            {
                "x": 180,
                "y": 140,
                "wires": [
                    {
                        "id": "93e904b826c5b927"
                    }
                ]
            }
        ],
        "out": [],
        "env": [],
        "meta": {},
        "color": "#DDAA99"
    },
    {
        "id": "ca1fc825888ca8ad",
        "type": "subflow:93d1b74d61d4f90f",
        "z": "5000652e2e0639f2",
        "name": "",
        "x": 520,
        "y": 140,
        "wires": []
    },
    {
        "id": "93e904b826c5b927",
        "type": "change",
        "z": "5000652e2e0639f2",
        "name": "",
        "rules": [
            {
                "t": "set",
                "p": "reset",
                "pt": "msg",
                "to": "true",
                "tot": "bool"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 320,
        "y": 140,
        "wires": [
            [
                "ca1fc825888ca8ad"
            ]
        ]
    },
    {
        "id": "93d1b74d61d4f90f",
        "type": "subflow",
        "name": "TestMsgCancel",
        "info": "",
        "category": "",
        "in": [
            {
                "x": 80,
                "y": 100,
                "wires": [
                    {
                        "id": "8e95cef841af3afe"
                    },
                    {
                        "id": "1b3f56701316f785"
                    }
                ]
            }
        ],
        "out": [],
        "env": [],
        "meta": {},
        "color": "#DDAA99"
    },
    {
        "id": "8e95cef841af3afe",
        "type": "delay",
        "z": "93d1b74d61d4f90f",
        "name": "",
        "pauseType": "delay",
        "timeout": "5",
        "timeoutUnits": "seconds",
        "rate": "1",
        "nbRateUnits": "1",
        "rateUnits": "second",
        "randomFirst": "1",
        "randomLast": "5",
        "randomUnits": "seconds",
        "drop": false,
        "allowrate": false,
        "outputs": 1,
        "x": 280,
        "y": 100,
        "wires": [
            [
                "f8bc75fb8ecb0338"
            ]
        ]
    },
    {
        "id": "f8bc75fb8ecb0338",
        "type": "debug",
        "z": "93d1b74d61d4f90f",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "\"delay finished\"",
        "targetType": "jsonata",
        "statusVal": "",
        "statusType": "auto",
        "x": 480,
        "y": 100,
        "wires": []
    },
    {
        "id": "1b3f56701316f785",
        "type": "debug",
        "z": "93d1b74d61d4f90f",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 270,
        "y": 40,
        "wires": []
    },
    {
        "id": "aa2a0675de682cbc",
        "type": "tab",
        "label": "Cancel Delay Works",
        "disabled": false,
        "info": "",
        "env": []
    },
    {
        "id": "e8c53ad359599fe8",
        "type": "inject",
        "z": "aa2a0675de682cbc",
        "name": "Set Delay",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "x": 120,
        "y": 140,
        "wires": [
            [
                "d04e986cf42f4425"
            ]
        ]
    },
    {
        "id": "77bd611303adafee",
        "type": "inject",
        "z": "aa2a0675de682cbc",
        "name": "Cancel Delay",
        "props": [
            {
                "p": "reset",
                "v": "true",
                "vt": "bool"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "x": 130,
        "y": 180,
        "wires": [
            [
                "d04e986cf42f4425"
            ]
        ]
    },
    {
        "id": "d04e986cf42f4425",
        "type": "subflow:93d1b74d61d4f90f",
        "z": "aa2a0675de682cbc",
        "name": "",
        "x": 340,
        "y": 140,
        "wires": []
    },
    {
        "id": "3433a4566b875615",
        "type": "comment",
        "z": "aa2a0675de682cbc",
        "name": "This works",
        "info": "This works setting msg.reset=true from within a flow",
        "x": 80,
        "y": 80,
        "wires": []
    },
    {
        "id": "1c1812546a3e8f75",
        "type": "inject",
        "z": "aa2a0675de682cbc",
        "name": "Cancel Delay",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "x": 130,
        "y": 320,
        "wires": [
            [
                "e66ae0ac72899773"
            ]
        ]
    },
    {
        "id": "78ab1eb439ec1abc",
        "type": "comment",
        "z": "aa2a0675de682cbc",
        "name": "This fails",
        "info": "This fails setting msg.reset=true from within a subflow",
        "x": 80,
        "y": 260,
        "wires": []
    },
    {
        "id": "e66ae0ac72899773",
        "type": "subflow:5000652e2e0639f2",
        "z": "aa2a0675de682cbc",
        "name": "",
        "x": 350,
        "y": 320,
        "wires": []
    }
]

Ok,

I see the problem.
A subflow is not a singleton

every subflow that is deployed is a new instance of the subflow.

Therefore Cancel Delay Failure fires up its own instance of TestMsgCancel

think of a subflow as a blueprint - not a single instance of something

If you press the set delay inject you'll see the delay is executed then the msg appears.
If you press the set delay under This Works then press the cancel delay you'll see the test subflow is invoked but the delay is cancelled and the msg after the delay does not appear.
If you press the set delay then the Cancel Delay under the This Fails you'll see the test subflow is invoked, the delay is executed, i.e., not cancelled, and the msg after the delay is executed

If you look inside the Cancel Delay Failure it sends the msg with reset=true to the TestMsgCancel subflow

So does that mean a delay initiated in any subflow can never be cancelled?

So does that mean a delay initiated in any subflow can never be cancelled?

If you wish to void a delay that is inside a subflow - then you must send the reset property to that (instance) of the subflow (or more accurately the delay node that is inside that subflow instance)

This is why your first one works - you are addressing the same subflow instance.

Each subflow has its own context - it does not share the context of its self globally

If you look inside the Cancel Delay Failure it sends the msg with reset=true to the TestMsgCancel subflow

Yes - but it is its own copy (or instance) of TestMsgCancel Therefore is not making any difference to the instance of TestMsgCancel that is in your main flow.

Like I said here

A subflow is not a singleton - every copy of your subflow In your main flow, has its own context and environment

If you do want something like a singleton then maybe the link-call node and return is an option .

1 Like

What is the best approach to doing this? Saving the original msg that invoked the subglow with the delay into a global var so it can be sent again to that same subflow with the reset=true? Does that send the msg to the same instance of that subflow?

If there is no easy way to do this I can always just use a global flag to tell the delayshutoff subflow whether to actually do the shut off.

You could use link-call nodes as suggested. That way there is only 1 set of nodes being operated on.

I don't understand what you mean by that. Each instance of the subflow is a node that appears in a flow in the editor. To send a message to a particular instance, that message needs to be sent down a wire into the node.

I have two flows A and B that both call subflow X. A calls subflow X to do a certain function that entails a delay node that delays 90 minutes. Flow B needs to cancel the delay in subflow X. My understanding is the reason it didn't work the way I first tried it was there are two instances of subflow X - X(A) and X(B). The delay has subflow X(A) stopped waiting for the delay to expire. When flow B tried to cancel it by calling subflow X it was actually sending the msg with reset=true to instance X(B) thus not cancelling the delay in X(A).

So the question was if I saved the message from within X(A) in a global var and then send it to a different instance of X does that actually send the message back to X(A)?