# Node-Red restarting on Uncaught Exception

**URL:** <https://discourse.nodered.org/t/node-red-restarting-on-uncaught-exception/84413>\
**Category:** General\
**Created:** [9 January 2024 10:27 UTC](https://discourse.nodered.org/t/node-red-restarting-on-uncaught-exception/84413 "2024-01-09T10:27:36Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![fmarzocca](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/fmarzocca/32/35901_2.png) [@fmarzocca](https://discourse.nodered.org/u/fmarzocca)\
**Post date:** [9 January 2024 10:27 UTC](https://discourse.nodered.org/t/node-red-restarting-on-uncaught-exception/84413/1 "2024-01-09T10:27:36Z")

</div>

During the night, I see that randomly NR restarts. These are the log lines:

```auto
2024-01-09T02:56:47.312255+01:00 PI4bOpenVPN Node-RED[29652]: 9 Jan 02:56:47 - [red] Uncaught Exception:
2024-01-09T02:56:47.313265+01:00 PI4bOpenVPN Node-RED[29652]: 9 Jan 02:56:47 - [error] Error: connect ECONNREFUSED 18.203.57.224:443
2024-01-09T02:56:47.313572+01:00 PI4bOpenVPN Node-RED[29652]: at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1555:16)
2024-01-09T02:56:47.390845+01:00 PI4bOpenVPN systemd[1]: nodered.service: Main process exited, code=exited, status=1/FAILURE

```

The IP is on amazonaws.

How can I proceed troubleshooting this or - at least - catch the error?

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [9 January 2024 13:45 UTC](https://discourse.nodered.org/t/node-red-restarting-on-uncaught-exception/84413/2 "2024-01-09T13:45:17Z")

</div>

Can you post the node-red startup log please, the one starting with the Welcome to node red message, and also the log leading up to the crash.

Also what node are you using to access amazonaws?

---

<div class="post-metadata">

**Author:** ![fmarzocca](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/fmarzocca/32/35901_2.png) [@fmarzocca](https://discourse.nodered.org/u/fmarzocca)\
**Post date:** [9 January 2024 20:23 UTC](https://discourse.nodered.org/t/node-red-restarting-on-uncaught-exception/84413/3 "2024-01-09T20:23:47Z")

</div>

@Colin These are the log lines leading up to the crash and the subsequent restart of NR. I don0t know which palette is using amazonaws, maybe Alexa?

```auto
2024-01-09T02:45:15.505655+01:00 PI4bOpenVPN Node-RED[29652]: 9 Jan 02:45:15 - [info] [ONVIF Snapshot:Ctronics] Fetching snapshot from HTTP://192.168.1.47:8080/onvif/device_service
2024-01-09T02:48:15.443772+01:00 PI4bOpenVPN Node-RED[29652]: 9 Jan 02:48:15 - [info] [ONVIF Snapshot:Ctronics] Fetching snapshot from HTTP://192.168.1.47:8080/onvif/device_service
2024-01-09T02:51:15.436431+01:00 PI4bOpenVPN Node-RED[29652]: 9 Jan 02:51:15 - [info] [ONVIF Snapshot:Ctronics] Fetching snapshot from HTTP://192.168.1.47:8080/onvif/device_service
2024-01-09T02:54:15.498536+01:00 PI4bOpenVPN Node-RED[29652]: 9 Jan 02:54:15 - [info] [ONVIF Snapshot:Ctronics] Fetching snapshot from HTTP://192.168.1.47:8080/onvif/device_service
2024-01-09T02:56:47.312255+01:00 PI4bOpenVPN Node-RED[29652]: 9 Jan 02:56:47 - [red] Uncaught Exception:
2024-01-09T02:56:47.313265+01:00 PI4bOpenVPN Node-RED[29652]: 9 Jan 02:56:47 - [error] Error: connect ECONNREFUSED 18.203.57.224:443
2024-01-09T02:56:47.313572+01:00 PI4bOpenVPN Node-RED[29652]: at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1555:16)
2024-01-09T02:57:07.562756+01:00 PI4bOpenVPN systemd[1]: Stopped nodered.service - Node-RED graphical event wiring tool.
2024-01-09T02:57:07.632822+01:00 PI4bOpenVPN systemd[1]: Started nodered.service - Node-RED graphical event wiring tool.
2024-01-09T02:57:09.536308+01:00 PI4bOpenVPN Node-RED[15958]: 9 Jan 02:57:09 - [info]
2024-01-09T02:57:09.536771+01:00 PI4bOpenVPN Node-RED[15958]: Welcome to Node-RED
2024-01-09T02:57:09.536918+01:00 PI4bOpenVPN Node-RED[15958]: ===================
2024-01-09T02:57:09.537974+01:00 PI4bOpenVPN Node-RED[15958]: 9 Jan 02:57:09 - [info] Node-RED version: v3.1.1
2024-01-09T02:57:09.539184+01:00 PI4bOpenVPN Node-RED[15958]: 9 Jan 02:57:09 - [info] Node.js version: v18.19.0
2024-01-09T02:57:09.539688+01:00 PI4bOpenVPN Node-RED[15958]: 9 Jan 02:57:09 - [info] Linux 6.1.0-rpi7-rpi-v7l arm LE
2024-01-09T02:57:10.734990+01:00 PI4bOpenVPN Node-RED[15958]: 9 Jan 02:57:10 - [info] Loading palette nodes
2024-01-09T02:57:15.509491+01:00 PI4bOpenVPN Node-RED[15958]: SmartthingsConfigNode
2024-01-09T02:57:15.510274+01:00 PI4bOpenVPN Node-RED[15958]: Creating directory: /home/pi/.node-red/smartthings/context/
2024-01-09T02:57:16.233174+01:00 PI4bOpenVPN Node-RED[15958]: 9 Jan 02:57:16 - [info] Dashboard version 3.6.2 started at /ui
2024-01-09T02:57:17.475820+01:00 PI4bOpenVPN Node-RED[15958]: 9 Jan 02:57:17 - [info] Settings file : /home/pi/.node-red/settings.js
2024-01-09T02:57:17.476151+01:00 PI4bOpenVPN Node-RED[15958]: 9 Jan 02:57:17 - [info] HTTP Static : /home/pi/.node-red/public > /
2024-01-09T02:57:17.482756+01:00 PI4bOpenVPN Node-RED[15958]: 9 Jan 02:57:17 - [info] Context store : 'default' [module=localfilesystem]
2024-01-09T02:57:17.484531+01:00 PI4bOpenVPN Node-RED[15958]: 9 Jan 02:57:17 - [info] Context store : 'RAM' [module=memory]
2024-01-09T02:57:17.510213+01:00 PI4bOpenVPN Node-RED[15958]: 9 Jan 02:57:17 - [info] User directory : /home/pi/.node-red
2024-01-09T02:57:17.510744+01:00 PI4bOpenVPN Node-RED[15958]: 9 Jan 02:57:17 - [warn] Projects disabled : editorTheme.projects.enabled=false
2024-01-09T02:57:17.513134+01:00 PI4bOpenVPN Node-RED[15958]: 9 Jan 02:57:17 - [info] Flows file : /home/pi/.node-red/flows.json
2024-01-09T02:57:17.540001+01:00 PI4bOpenVPN Node-RED[15958]: 9 Jan 02:57:17 - [info] Server now running at http://127.0.0.1:1880/
2024-01-09T02:57:17.600514+01:00 PI4bOpenVPN Node-RED[15958]: 9 Jan 02:57:17 - [warn]
2024-01-09T02:57:17.600734+01:00 PI4bOpenVPN Node-RED[15958]: ---------------------------------------------------------------------
2024-01-09T02:57:17.600857+01:00 PI4bOpenVPN Node-RED[15958]: Your flow credentials file is encrypted using a system-generated key.

```

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [10 January 2024 08:36 UTC](https://discourse.nodered.org/t/node-red-restarting-on-uncaught-exception/84413/4 "2024-01-10T08:36:01Z")

</div>

> [@fmarzocca](#):
>
> maybe Alexa

If you search the forum for  
TCPConnectWrap.afterConnect  
you will find this has been reported before with Alexa related nodes. I don't use Alexa so don't know if there is a solution.

Perhaps someone else who knows about Alexa can help.

---

<div class="post-metadata">

**Author:** ![fmarzocca](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/fmarzocca/32/35901_2.png) [@fmarzocca](https://discourse.nodered.org/u/fmarzocca)\
**Post date:** [10 January 2024 10:14 UTC](https://discourse.nodered.org/t/node-red-restarting-on-uncaught-exception/84413/5 "2024-01-10T10:14:06Z")

</div>

> [@Colin](#):
>
> TCPConnectWrap.afterConnect

Yes, but why an Uncaught Exception and NR restarting for a normal ERRCONNREFUSED? I am confused.

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [10 January 2024 10:33 UTC](https://discourse.nodered.org/t/node-red-restarting-on-uncaught-exception/84413/6 "2024-01-10T10:33:35Z")

</div>

If a node doesn't handle Uncaught Exceptions, the runtime can be left in an indeterminate state and the safest thing to do is to let it crash. There are a ton of articles and discussions around this but lets just say ignoring errors will almost always leave your application in a bad state, whether that's having a memory leak or leaving sockets hanging or ...

In short, the author of a node should explicitly handle errors and clean up in their nodes - raise an issue on the repository.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [24 January 2024 10:33 UTC](https://discourse.nodered.org/t/node-red-restarting-on-uncaught-exception/84413/7 "2024-01-24T10:33:55Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
