lorenwest / node-red-contrib-state

Node-RED shared logical state with persistence, notification, and history
MIT License
7 stars 6 forks source link

Getting multiple state change events for single change #14

Closed hannuterasloihde closed 1 year ago

hannuterasloihde commented 1 year ago

I have one flow (on one tab) which sets the state node and a second flow where I get the state.

If I deploy only the modified flows this results in any change to the state to be replicated multiple times (2-4) on the second flow.

If I do a full deploy the situation is corrected and it works correctly and I get a single event on the second flows get state.

This is not reproducable if the setting and getting of the state are in the same flow diagram even if I only deploy the modified flows.

My node is only listening to the state change events.

lorenwest commented 1 year ago

This sounds like an anomaly of Node-RED, where partial re-deploys perform partial re-initialization.

If you rely on the number of times the get state is run, I suggest either always doing a full deploy or, since this is an open source project, figuring out if there's a way to detect this situation and prevent re-initialization of the stats node.

hannuterasloihde commented 1 year ago

I also wasn't getting the state persisted to filesystem. After a bit of searching the reason is that the setting 'Keep history' needs to be set to >0, otherwise it won't persist the state. As I didn't require the old history values I had set this to zero. After I changed this setting the original problem seems to have also disappeared.