Node-RED "502: Bad Gateway" from UnhandledPromiseRejection

I’ve been down a rabbit hole for a few days here with a 502 Bad Gateway error on my Node-RED. My system’s been stable for quite a while and I was just making a couple of changes on devices. On one of my reboots, Node-RED started throwing the 502 error and I can’t figure out how to fix it.

I’ve read past posts and tried the suggestions around the SSL settings which have been set to True for years - I run DuckDNS and Nabu Casa and have certs in the SSL folder. Even so I changed it to False and back to True many times with no effect.

I have an unique password for credential_secret that hasn’t been pwned, the same one I’ve used for years.

I also tried the browser cache clearing both through the settings of the browsers and with shift-F5 on the page. No joy.

I’ve restored five separate full backups, four of which I know had Node-RED working fine. And somehow, still have the 502.

If I completely uninstall Node-RED and rename the Node-RED file folder, it will reinstall and run properly. However I can’t figure out how to retain all my nodes and flows that I’ve created (and there’s a lot!). I can’t find any posts that talk about how to do a fresh install and then bring in your old flows and nodes.

Below is my log. It shows a strange UnhandledPromiseRejection error which I guess is the problem but I have no idea where to go from here.

If any one can shed a little light I am very grateful.


s6-rc: info: service s6rc-oneshot-runner: starting
s6-rc: info: service s6rc-oneshot-runner successfully started
s6-rc: info: service fix-attrs: starting
s6-rc: info: service fix-attrs successfully started
s6-rc: info: service legacy-cont-init: starting
cont-init: info: running /etc/cont-init.d/00-banner.sh

Add-on: Node-RED
Flow-based programming for the Internet of Things

Add-on version: 12.0.2
You are running the latest version of this add-on.
System: Debian GNU/Linux 11 (bullseye) (amd64 / qemux86-64)
Home Assistant Core: 2022.7.0
Home Assistant Supervisor: 2022.06.2

Please, share the above information when looking for help
or support in, e.g., GitHub, forums or the Discord chat.

cont-init: info: /etc/cont-init.d/00-banner.sh exited 0
cont-init: info: running /etc/cont-init.d/01-log-level.sh
cont-init: info: /etc/cont-init.d/01-log-level.sh exited 0
cont-init: info: running /etc/cont-init.d/customizations.sh
cont-init: info: /etc/cont-init.d/customizations.sh exited 0
cont-init: info: running /etc/cont-init.d/nginx.sh
cont-init: info: /etc/cont-init.d/nginx.sh exited 0
cont-init: info: running /etc/cont-init.d/node-red.sh
patching file nodes/ui_base.html
Hunk #1 succeeded at 1164 (offset 633 lines).
up to date, audited 1022 packages in 21s
34 packages are looking for funding
run npm fund for details
51 vulnerabilities (1 low, 19 moderate, 24 high, 7 critical)
To address issues that do not require attention, run:
npm audit fix
To address all issues (including breaking changes), run:
npm audit fix --force
Run npm audit for details.
cont-init: info: /etc/cont-init.d/node-red.sh exited 0
s6-rc: info: service legacy-cont-init successfully started
s6-rc: info: service legacy-services: starting
services-up: info: copying legacy longrun nginx (no readiness notification)
services-up: info: copying legacy longrun nodered (no readiness notification)
s6-rc: info: service legacy-services successfully started
[21:48:02] INFO: Starting Node-RED…

start
node $NODE_OPTIONS node_modules/node-red/red.js “–settings” “/etc/node-red/config.js”
6 Jul 21:48:04 - [info]
Welcome to Node-RED
===================
6 Jul 21:48:04 - [info] Node-RED version: v2.2.2
6 Jul 21:48:04 - [info] Node.js version: v16.15.0
6 Jul 21:48:04 - [info] Linux 5.10.0-15-amd64 x64 LE
6 Jul 21:48:05 - [info] Loading palette nodes
6 Jul 21:48:10 - [info] Dashboard version 3.1.3 started at /endpoint/ui
6 Jul 21:48:12 - [warn] ------------------------------------------------------
6 Jul 21:48:12 - [warn] [node-red-node-rbe/rbe] ‘rbe’ already registered by module node-red
6 Jul 21:48:12 - [warn] ------------------------------------------------------
6 Jul 21:48:12 - [info] Settings file : /etc/node-red/config.js
6 Jul 21:48:12 - [info] Context store : ‘default’ [module=memory]
6 Jul 21:48:12 - [info] User directory : /config/node-red/
6 Jul 21:48:12 - [warn] Projects disabled : editorTheme.projects.enabled=false
6 Jul 21:48:12 - [info] Flows file : /config/node-red/flows.json
6 Jul 21:48:12 - [info] Server now running at http://127.0.0.1:46836/
6 Jul 21:48:13 - [info] Starting flows
[21:48:13] INFO: Starting NGinx…
6 Jul 21:48:15 - [info] Started flows
(node:323) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 error listeners added to [EventEmitter]. Use emitter.setMaxListeners() to increase limit
(Use node --trace-warnings ... to show where the warning was created)
6 Jul 21:48:15 - [info] [mqtt-broker:431743e8.b8636c] Connected to broker: node-red@mqtt://192.168.1.213:1883
6 Jul 21:48:15 - [info] [mqtt-broker:49430200.b1a6b] Connected to broker: mqtt://192.168.1.213:1883
6 Jul 21:48:15 - [red] Uncaught Exception:
6 Jul 21:48:15 - [error] UnhandledPromiseRejection: This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). The promise rejected with the reason “{“error”:403,“msg”:“Sign:oauthClient enable invalid”}”.
[21:48:15] WARNING: Node-RED crashed, halting add-on
s6-rc: info: service legacy-services: stopping
[21:48:15] INFO: Node-RED stoped, restarting…
[21:48:15] INFO: Node-RED stoped, restarting…
s6-svwait: fatal: supervisor died
s6-rc: info: service legacy-services successfully stopped
s6-rc: info: service legacy-cont-init: stopping
s6-rc: info: service legacy-cont-init successfully stopped
s6-rc: info: service fix-attrs: stopping
s6-rc: info: service fix-attrs successfully stopped
s6-rc: info: service s6rc-oneshot-runner: stopping
s6-rc: info: service s6rc-oneshot-runner successfully stopped


Not really going to help, but I am getting exactly the same issue since about 8 pm last night.

In the past a full reinstall fixed 502’s back up all flows, remove the addon, rename the NR folder to .old. Reboot the host to reinstall.

Reboot the host is different from restarting home assistant. They’ve moved things around and I’m not sure how to do in the gui. If you go to dev tools → service and call the service hassio.host_reboot then reinstall. Once things are up and running delete the old nodered folder.

1 Like

Thanks @Mikefila.

I did try a clean full reinstall, just as you say. Node-RED does spin up properly then. But I don’t know how to properly restore my flows, downloaded nodes, and settings. Do you know how to fully restore the old Node-RED flows etc. in a clean reinstall?

In digging in more, I can see that this UnhandledPromiseRejection error is apparently causing the Node-RED container to stop. I can restart it in Portainer, it runs fine, and then during the Node-RED initialization when it crashes it stops the container. Weird.

I haven’t found the new spot for rebooting the host either. If I need to do that I’ve been power-cycling my NUC.

I found reboot host, you really should avoid flipping the switch. That should be a last resort. I found it in settings, system, hardware, three dots in the right corner, reboot host.

To restore the flows right where you exported them, there is the import option. ctrl i is the keyboard shortcut.

1 Like

I have the same problem.

Thanks again @Mikefila. I found and noted the reboot host feature for future use. Import flows worked for me after a clean reinstall. I’m going to write up a separate post with the steps I followed to restore my Node-RED, to help other folks who might find themselves in the same situation.

I have an clean installation of HA 2022.8.5 and installed Node-Red 13.3.1

I got the “502: Bad Gateway” when I try to open the “Node-RED”… then I got “Node-RED, Add-on is not running. Please start it first”…

If I start up Node-RED again I get the same error and then it stops… so what can I do to get this working?