I expect I'm being thick or just tired but I am having a problem with persistent context stores.
No, I'm not being thick, I can see the problem happening. It is because there is a delay of around 30 seconds before persistent variables are written to the fs. While that is fine normally, Node-RED, I think, should flush its cache when stopping but it doesn't.
A bug? Is there a work-around?
Given the following flow. If I press the top inject, it correctly outputs "fred" from the flow._test
variable that uses the file
persistent store. I can press the bottom inject and get the same result as expected.
However, if I press the top inject, then restart Node-RED, the output is undefined
which is obviously not what I'd expect.
[{"id":"d055686e.e26f28","type":"inject","z":"5cf69d1b.d88c14","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":315,"y":500,"wires":[["1b20e9a0.2000b6"]],"l":false},{"id":"1b20e9a0.2000b6","type":"change","z":"5cf69d1b.d88c14","name":"","rules":[{"t":"set","p":"#:(file)::_test","pt":"flow","to":"fred","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":440,"y":500,"wires":[["34ef3970.7bb026"]]},{"id":"8f47d888.d531a8","type":"debug","z":"5cf69d1b.d88c14","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":830,"y":500,"wires":[]},{"id":"cdcf8b32.90b248","type":"inject","z":"5cf69d1b.d88c14","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":495,"y":560,"wires":[["34ef3970.7bb026"]],"l":false},{"id":"34ef3970.7bb026","type":"change","z":"5cf69d1b.d88c14","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"#:(file)::_test","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":640,"y":500,"wires":[["8f47d888.d531a8"]]}]
And in settings.js
:
contextStorage: {
default: {
module:'memory'
},
file: {
module: 'localfilesystem'
}
},
30 Jan 22:37:08 - [info] Node-RED version: v1.0.3
30 Jan 22:37:08 - [info] Node.js version: v12.14.0
30 Jan 22:37:08 - [info] Windows_NT 10.0.18363 x64 LE
Incidentally, you can see the same thing just by using the context sidebar. Write to a flow variable (it happens with flow, node and global). Wait 30 sec. Then delete the variable using the icon in the sidebar and either stop the Node-RED process or restart it within 30 sec. When you restart, the variable will still be there.