Node-red dashboard "refused to connect"

I am having a problem with my node-red. I am running node-red on a windows 10 PC and using node-red-dashboard as UI. The problem is that sometimes when I get power outage, the node-red stops working. In the browser it says "refused to connect", to the adress 128.1.11.3:1880/ui/.
How I solve the problem:
I delete the context folder in the node-red folder.
Then I restart the PC and starting node-red.

What could cause this problem?
How should I locate the problem so I can get rid of this?

Welcome to the forum @larro96

Is node-red running? Can you connect to the editor at 128.1.11.3:1880?

Does that fix it? If not show us what you see in the command window when you start node-red.

If that does fix it, does just restarting node-red fix it (without clearing the context)? If not then, again, show us what you get in the command window when you restart node-red.

Node-red is running and I can connect to the editor.

My solution is solving the problem, just restarting node-red doesn't.
I'll get some screenshots next time it crashes.

No, copy/paste the output please.

1 Like

Here is the output:
Your environment has been set up for using Node.js 18.15.0 (x64) and npm.

C:\Users\Pc>node-red
27 May 06:33:35 - [info]

Welcome to Node-RED
===================

27 May 06:33:35 - [info] Node-RED version: v3.0.2
27 May 06:33:35 - [info] Node.js  version: v18.15.0
27 May 06:33:35 - [info] Windows_NT 10.0.19045 x64 LE
27 May 06:33:38 - [info] Loading palette nodes
27 May 06:33:44 - [info] Dashboard version 3.4.0 started at /ui
27 May 06:33:44 - [info] Settings file  : C:\Users\Pc\.node-red\settings.js
27 May 06:33:44 - [info] Context store  : 'default' [module=localfilesystem]
27 May 06:33:44 - [error] Failed to start server:
27 May 06:33:44 - [error] Error: Error loading context store: Error: Invalid JSON in context file '\Users\Pc\.node-red\context\b1531b115956bc02\dcea7f832804799a.json'
    at C:\Users\Pc\AppData\Roaming\npm\node_modules\node-red\node_modules\@node-red\runtime\lib\nodes\context\index.js:180:15

C:\Users\Pc>node-red
27 May 06:36:12 - [info]

Welcome to Node-RED
===================

27 May 06:36:12 - [info] Node-RED version: v3.0.2
27 May 06:36:12 - [info] Node.js  version: v18.15.0
27 May 06:36:12 - [info] Windows_NT 10.0.19045 x64 LE
27 May 06:36:15 - [info] Loading palette nodes
27 May 06:36:20 - [info] Dashboard version 3.4.0 started at /ui
27 May 06:36:20 - [info] Settings file  : C:\Users\Pc\.node-red\settings.js
27 May 06:36:20 - [info] Context store  : 'default' [module=localfilesystem]
27 May 06:36:20 - [error] Failed to start server:
27 May 06:36:20 - [error] Error: Error loading context store: Error: Invalid JSON in context file '\Users\Pc\.node-red\context\b1531b115956bc02\dcea7f832804799a.json'
    at C:\Users\Pc\AppData\Roaming\npm\node_modules\node-red\node_modules\@node-red\runtime\lib\nodes\context\index.js:180:15

C:\Users\Pc>node-red
27 May 06:41:40 - [info]

Welcome to Node-RED
===================

27 May 06:41:40 - [info] Node-RED version: v3.0.2
27 May 06:41:40 - [info] Node.js  version: v18.15.0
27 May 06:41:40 - [info] Windows_NT 10.0.19045 x64 LE
27 May 06:41:43 - [info] Loading palette nodes
27 May 06:41:49 - [info] Dashboard version 3.4.0 started at /ui
27 May 06:41:49 - [info] Settings file  : C:\Users\Pc\.node-red\settings.js
27 May 06:41:49 - [info] Context store  : 'default' [module=localfilesystem]
27 May 06:41:49 - [error] Failed to start server:
27 May 06:41:49 - [error] Error: Error loading context store: Error: Invalid JSON in context file '\Users\Pc\.node-red\context\backup 240527\dcea7f832804799a.json'
    at C:\Users\Pc\AppData\Roaming\npm\node_modules\node-red\node_modules\@node-red\runtime\lib\nodes\context\index.js:180:15

C:\Users\Pc>node-red
27 May 06:42:10 - [info]

Welcome to Node-RED
===================

27 May 06:42:10 - [info] Node-RED version: v3.0.2
27 May 06:42:10 - [info] Node.js  version: v18.15.0
27 May 06:42:10 - [info] Windows_NT 10.0.19045 x64 LE
27 May 06:42:12 - [info] Loading palette nodes
27 May 06:42:18 - [info] Dashboard version 3.4.0 started at /ui
27 May 06:42:18 - [info] Settings file  : C:\Users\Pc\.node-red\settings.js
27 May 06:42:18 - [info] Context store  : 'default' [module=localfilesystem]
27 May 06:42:18 - [info] User directory : \Users\Pc\.node-red
27 May 06:42:18 - [warn] Projects disabled : editorTheme.projects.enabled=false
27 May 06:42:18 - [info] Flows file     : \Users\Pc\.node-red\flows.json
27 May 06:42:18 - [info] Server now running at http://127.0.0.1:1880/
27 May 06:42:19 - [warn]

---------------------------------------------------------------------
Your flow credentials file is encrypted using a system-generated key.

If the system-generated key is lost for any reason, your credentials
file will not be recoverable, you will have to delete it and re-enter
your credentials.

You should set your own key using the 'credentialSecret' option in
your settings file. Node-RED will then re-encrypt your credentials
file using your chosen key the next time you deploy a change.
---------------------------------------------------------------------

27 May 06:42:19 - [info] Starting flows
Connection options, transport settings: {}
Connection options, transport settings: {}
Connection options, transport settings: {}
Connection options, transport settings: {}
27 May 06:42:19 - [info] Started flows
04:42:25.194Z :populate_data_type_manager_104:51     Cannot find dataType Definition ! with nodeId =ns=2;i=6525
04:42:25.592Z :populate_data_type_manager_104:51     Cannot find dataType Definition ! with nodeId =ns=2;i=15889
04:42:25.600Z :populate_data_type_manager_104:51     Cannot find dataType Definition ! with nodeId =ns=2;i=15888

The problem apeared when the pc was turned off during the weekend and then was started this morning.

Can you locate the problem in the output I posted?

I have editted your post to add tripple backticks around the output so that the forum does not interpret it a markdown.

Did you do anything between those run attempts? If you did not then the file system is not giving you consistent data so you have something very wrong with your system. I don't know much about Windows so can't really help much with that. You probably want to make sure everything is backed up and then run a check disk operation.

Thanks,
for the first three attempts I tried to delete different files in the folder "C:\Users\Pc\AppData\Roaming\npm\node_modules\node-red\node_modules@node-red\runtime\lib\nodes\context" but it didn't help.
Last time I deleted the files inte the folder "\Users\Pc.node-red\context" and then it starts without problem.

Deleting anything inside "C:\Users\Pc\AppData\Roaming\npm\node_modules\node-red\node_modules@node-red\*** will break Node-RED! Those are the actual source code files that makes Node-RED run (they are not data files that can be simply cleaned up!)

Understood.

Do you have any solution on my problem?

You said that you had deleted the context file and it started without problems, so it isn't clear what is not working for you.

Okay, if I turn off the PC now for a weekend then I will get the same problem when I start the PC.

I've deleted the files in the context folder about 5 times this year because of power outage.

Do you mean you get the corruption even when there has not been a power outage?

I suggest you upgrade to the latest version of node red. I am not aware of any changes in that area since 3.0.2 but you need to upgrade first just in case.

The next time it happens, post the contents of the file before deleting it.

No, the corruption only happens after power outage.

Okay, I will try that.

I've saved all the files from the context folder from each corruption, shall I post them here as a archived folder?

Just post a typical one.

Do you have any other problems with your machine after an outage?

I could not upload a archived folder here so you can download it from here:
https://sprend.com/download?C=5d93f86b7b1c4de2a4af9bc4b39c7b2a

I do not have problem with anything else, after an outage I have to delete the context folder and start node-red, then the machine is up and running fine.

The b1531b115956bc02 in that error message is the ID of an editor tab.
It would be useful to see an export of that tab too.

There may be a simple way to get the tab name (the "label" property) from the ID but I'm not aware how, so here is a flow to extract it from the flows file (you might need to change the flows file pathname)

[{"id":"e354973541e14b65","type":"inject","z":"e56de693d0e0a509","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"b1531b115956bc02","payloadType":"str","x":210,"y":100,"wires":[["4cf75cfcb9feb511"]]},{"id":"f3fdbbee199ddbdd","type":"file in","z":"e56de693d0e0a509","name":"","filename":".node-red/flows.json","filenameType":"str","format":"utf8","chunk":false,"sendError":false,"encoding":"none","allProps":false,"x":200,"y":160,"wires":[["9a585a43f3963148"]]},{"id":"59168d428a3de93c","type":"switch","z":"e56de693d0e0a509","name":"","property":"payload.id","propertyType":"msg","rules":[{"t":"eq","v":"chosenNodeId","vt":"flow"}],"checkall":"true","repair":false,"outputs":1,"x":290,"y":220,"wires":[["bc7fbdf1c70efe94"]]},{"id":"9a585a43f3963148","type":"json","z":"e56de693d0e0a509","name":"","property":"payload","action":"","pretty":false,"x":490,"y":160,"wires":[["43b49091765ec263"]]},{"id":"bc7fbdf1c70efe94","type":"debug","z":"e56de693d0e0a509","name":"debug 115","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":450,"y":220,"wires":[]},{"id":"43b49091765ec263","type":"split","z":"e56de693d0e0a509","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":150,"y":220,"wires":[["59168d428a3de93c"]]},{"id":"4cf75cfcb9feb511","type":"change","z":"e56de693d0e0a509","name":"","rules":[{"t":"set","p":"chosenNodeID","pt":"flow","to":"","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":440,"y":100,"wires":[["f3fdbbee199ddbdd"]]}]

Can you show us what is on that editor tab? A screen capture would help but an export is always better.

1 Like

We don't want to see the whole folder, just one of the files that it complained about.

dcea7f832804799a.json (20 Bytes)
Okay, this one then.