I'm seeing a lot of error-circular messages and I'm wondering if this is caused by "my way" of handling persistent global variables (I'm storing some historic values, e.g. the highest/lowest temperature seen):
I enabled the Local Filesystem Context Storage
At startup I do the following for every global variable once:
var globVar = global.get('globVar');
globVar = false; // Example for a boolean value
global.set('globVar ', globVar);
If I want to access the variable I do the following:
var globVar = global.get('globVar'); //
... calculate something here...
Could this cause the error-circular warnings? What is the right way of handling global variables (I know, best way is to don't use them at all)?
thanks a lot for your help. Unfortunately I'm just beginning with Node Red and I'm struggling to provide the full output of the error - Where can I find this information?
Node-Red-Log just provides the warning itself without any additional information, e.g. "2 Jan 13:28:38 - [warn] error-circular". Same for my debug nodes, e.g. 2.1.2020, 13:57:09 msg : string "error-circular".
So far I struggled to identify the affected node(s), but while writing this message I noticed that I can try to identify the affected nodes by setting one inject to 10s and the rest to 1 hour.
Q: What sorts of values are you storing in context? Simple values or more complex objects?
A: Just simple values like int, float or boolean
Q: If they are objects, how are they generated and do they contain circular references in them?
A: To be honest: I'm not sure, but as I'm just storing simple values I think the answer is "no circular references"
If you name your nodes then it should show the node name in the debug window above the message. It does show an id anyway, but it is easier to track them down if you use names. The Search feature will let you search the flow for a name or an id, or anything else for that matter.
I dont think naming my nodes will help. Unfortunately the error message doesn't even show the usual node ID (see above). And >95% of my nodes are named anyhow.
I added two nodes (a Catch node connected to a debug node) to see if I get more information. I tried that on every tab but it seems this kind of error is not caught by a catch node. At least I did not get any further information. Just the error message posted above without a node ID.
Ok, I still was not able to find the root cause of my problem, however I found out that it's related to the "Local Filesystem Context Store". I uninstalled NR completely and after a re-installation everything was fine. But once I activated the local file storage the error-circulars started again.
As a workaround I increased the flushInterval to 10 minutes and now the amount of errors has decreased significantly, but they are still there.
The error comes whenever the File Store has to encode your context data to JSON so it can be written to the file. This is why changing the flush interval to 10 minutes will mean you hit the error 10 minutes after updating the context rather than the default 30 seconds.
Yes. Somehow you are putting something into context that includes a circular reference.
Changing the rate of your inject nodes won't change the logic of your flows or the nature of the objects you are trying to store.
So the question again comes back to what sort of data are you trying to store in context.
A good example that came up today was a user trying to store the value returned by setInterval() into context. This value is a complex object with circular references and cannot be converted to JSON.
I indeed didn't understand that the storing process could just be the symptom, not the issue. So thanks for pointing this out.
Does it make sense to compare the File Store (/home/pi/.node-red/context/global/global.json I guess?) with my context data shown in NR? My understanding is that a missing global in the file would indicate the problem, correct?
Everything seems to be ok. Every Global shown in NR is stored in /home/pi/.node-red/context/global/global.json with the value I would expect to see.
Out of 15 Globals 14 are simple types (String, Boolean, Int, Float) and one is automatically generated by a node I installed (https://flows.nodered.org/node/node-red-contrib-homee). The last one is huge, so I'm struggling to compare all values. But as it is stored I guess it should be ok.