# Nodered container crash everyday

**URL:** <https://discourse.nodered.org/t/nodered-container-crash-everyday/86933>\
**Category:** General\
**Tags:** docker\
**Created:** [2 April 2024 10:07 UTC](https://discourse.nodered.org/t/nodered-container-crash-everyday/86933 "2024-04-02T10:07:39Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![Barbudor](https://avatars.discourse-cdn.com/v4/letter/b/4af34b/32.png) [@Barbudor](https://discourse.nodered.org/u/Barbudor)\
**Post date:** [2 April 2024 10:07 UTC](https://discourse.nodered.org/t/nodered-container-crash-everyday/86933/1 "2024-04-02T10:07:39Z")

</div>

Hello

Since a week I facing a strange crash on one of my nodered container (running in AWS ECS on a FARGATE instance)  
There is no memory or CPU overload but something seems to happen that I have not been able to identify  
Nodered version is 3.0.2, default docker imagebased on node 16.20.2

You would says that as it happens everyday at the same hour it should be easy to identify the guilty flow but actually I don't have any flow that start at that time, so I'm a bit clue less

Here is what I see in the logs prior to the crash:

```auto
2 Apr 09:17:11 - [red] Uncaught Exception:
at processImmediate (node:internal/timers:466:21)
at Immediate.<anonymous> (/usr/src/node-red/node_modules/@node-red/runtime/lib/flows/Flow.js:831:52)
2 Apr 09:17:11 - [error] TypeError: sendEvent.destination.node.receive is not a function
'===================
Welcome to Node-RED
2 Apr 09:18:06 - [info]

```

I also noticed that just after restart there are those errors that I can't neither link to something:

```auto
2 Apr 09:18:49 - [warn]
2 Apr 09:18:49 - [info] Starting flows
TypeError: Cannot read properties of undefined (reading 'id')
at Object.start [as startFlows] (/usr/src/node-red/node_modules/@node-red/runtime/lib/flows/index.js:394:33)
at Flow.start (/usr/src/node-red/node_modules/@node-red/runtime/lib/flows/Flow.js:224:41)
at Subflow.start (/usr/src/node-red/node_modules/@node-red/runtime/lib/flows/Subflow.js:209:62)
at Array.map (<anonymous>)
at /usr/src/node-red/node_modules/@node-red/runtime/lib/flows/Subflow.js:209:95
at Array.map (<anonymous>)
at /usr/src/node-red/node_modules/@node-red/runtime/lib/flows/Subflow.js:209:140
2 Apr 09:19:23 - [info] [mongodb-aleph-in:find in custom_metadata] connecting to mongodb...
at Object.start [as startFlows] (/usr/src/node-red/node_modules/@node-red/runtime/lib/flows/index.js:394:33)
at Flow.start (/usr/src/node-red/node_modules/@node-red/runtime/lib/flows/Flow.js:224:41)
at Subflow.start (/usr/src/node-red/node_modules/@node-red/runtime/lib/flows/Subflow.js:209:62)
at Array.map (<anonymous>)
at /usr/src/node-red/node_modules/@node-red/runtime/lib/flows/Subflow.js:209:95
at Array.map (<anonymous>)
at /usr/src/node-red/node_modules/@node-red/runtime/lib/flows/Subflow.js:209:140
TypeError: Cannot read properties of undefined (reading 'id')
2 Apr 09:19:23 - [info] Started flows
(Use `node --trace-warnings ...` to show where the warning was created)

```

Any advice to help tracking down where this could happen would be appreciated  
Thanks

---

<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:** [2 April 2024 10:28 UTC](https://discourse.nodered.org/t/nodered-container-crash-everyday/86933/2 "2024-04-02T10:28:23Z")

</div>

> [@Barbudor](#):
>
> `(Use `node --trace-warnings ...` to show where the warning was created)`

Try setting the log level to Trace in settings.js in the hope it will give more information.

---

<div class="post-metadata">

**Author:** ![Barbudor](https://avatars.discourse-cdn.com/v4/letter/b/4af34b/32.png) [@Barbudor](https://discourse.nodered.org/u/Barbudor)\
**Post date:** [2 April 2024 16:18 UTC](https://discourse.nodered.org/t/nodered-container-crash-everyday/86933/3 "2024-04-02T16:18:21Z")

</div>

Thanks @Colin

I made the change and will restart the container at night  
Then we will see if it crashes again tomorrow

---

<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:** [2 April 2024 20:27 UTC](https://discourse.nodered.org/t/nodered-container-crash-everyday/86933/4 "2024-04-02T20:27:02Z")

</div>

> [@Barbudor](#):
>
> we will see if it crashes again tomorrow

The Trace setting is more about determining what is causing the errors on startup. Though it may give information about the crash too, but less likely.

---

<div class="post-metadata">

**Author:** ![Barbudor](https://avatars.discourse-cdn.com/v4/letter/b/4af34b/32.png) [@Barbudor](https://discourse.nodered.org/u/Barbudor)\
**Post date:** [4 April 2024 07:58 UTC](https://discourse.nodered.org/t/nodered-container-crash-everyday/86933/5 "2024-04-04T07:58:09Z")

</div>

Ah thanks  
However I now have the traces for both

**Here are the logs right before the crash**

```auto
2024-04-04T06:31:37.086Z	4 Apr 06:31:37 - [debug] Flushing localfilesystem context scope 304d6298862b9e4b
2024-04-04T06:34:56.412Z	4 Apr 06:34:56 - [debug] Flushing localfilesystem context scope 304d6298862b9e4b
2024-04-04T06:37:27.891Z	at processImmediate (node:internal/timers:466:21)
2024-04-04T06:37:27.891Z	at Immediate.<anonymous> (/usr/src/node-red/node_modules/@node-red/runtime/lib/flows/Flow.js:831:52)
2024-04-04T06:37:27.891Z	4 Apr 06:37:27 - [error] TypeError: sendEvent.destination.node.receive is not a function
2024-04-04T06:37:27.891Z	4 Apr 06:37:27 - [red] Uncaught Exception:
2024-04-04T06:38:40.550Z	'===================
2024-04-04T06:38:40.550Z	Welcome to Node-RED

```

I found this [Github issue](https://github.com/node-red/node-red/issues/3848) which refers to using `node.send()`into a promise call back which I'm actually using in a function node:

```auto
// Initialize slack
const web = new slackWebApi.WebClient("xxxxxxxxxxxxxxxxxxxxxx");

node.warn(`Slack upload with ${JSON.stringify(msg.payload)}`);

(async () => {
    const result = await web.files.uploadV2(msg.payload);
    msg.payload = result
    node.send(msg)
})();

```

If this is to be avoided, could you please advise how I should code that instead ?

**And the logs during boot issue are those:**

```auto
2024-04-04T06:39:45.286Z	4 Apr 06:39:45 - [trace] [subflow:be049e0bbf73290d] ------------------|--------------|-----------------
2024-04-04T06:39:45.286Z	4 Apr 06:39:45 - [trace] [subflow:be049e0bbf73290d] start subflow [cdb37cb8bad2f69e/e7ee7117246f4ae3/cab9972dcf655114/09507900c4b343fe]
2024-04-04T06:39:45.286Z	4 Apr 06:39:45 - [trace] [subflow:1cc39ec7a53d287e] start subflow [cdb37cb8bad2f69e/e7ee7117246f4ae3/cab9972dcf655114]
2024-04-04T06:39:45.286Z	4 Apr 06:39:45 - [trace] [subflow:e7ee7117246f4ae3] start subflow [cdb37cb8bad2f69e/e7ee7117246f4ae3]
2024-04-04T06:39:45.288Z	at Object.start [as startFlows] (/usr/src/node-red/node_modules/@node-red/runtime/lib/flows/index.js:394:33)
2024-04-04T06:39:45.288Z	at Flow.start (/usr/src/node-red/node_modules/@node-red/runtime/lib/flows/Flow.js:224:41)
2024-04-04T06:39:45.288Z	at Subflow.start (/usr/src/node-red/node_modules/@node-red/runtime/lib/flows/Subflow.js:209:62)
2024-04-04T06:39:45.288Z	at Array.map (<anonymous>)
2024-04-04T06:39:45.288Z	at /usr/src/node-red/node_modules/@node-red/runtime/lib/flows/Subflow.js:209:95
2024-04-04T06:39:45.288Z	at Array.map (<anonymous>)
2024-04-04T06:39:45.288Z	at /usr/src/node-red/node_modules/@node-red/runtime/lib/flows/Subflow.js:209:140
2024-04-04T06:39:45.288Z	TypeError: Cannot read properties of undefined (reading 'id')
2024-04-04T06:39:45.302Z	4 Apr 06:39:45 - [debug] [subflow:2f9f934b3ee78deb] not starting disabled node : 6388487f96043b52
2024-04-04T06:39:45.302Z	4 Apr 06:39:45 - [trace] [subflow:2f9f934b3ee78deb] start subflow [1ee34aef2976ed38/2f9f934b3ee78deb]
2024-04-04T06:39:45.303Z	4 Apr 06:39:45 - [trace] [subflow:2f9f934b3ee78deb] ------------------|--------------|-----------------

```

Which seems to locate the problem in subflow `e7ee7117246f4ae3`  
The problem seems to occur in that line (node-red3.0.2):

> <https://github.com/node-red/node-red/blob/5365786386e21df74b339a399e854ed89af6394f/packages/node_modules/%40node-red/runtime/lib/flows/Subflow.js#L209>

One of the 2 `.id` seems to be non existant

Any idea what could cause that ?  
We have other node-red instances running in similar conditions (other AWS regions) with same nodes and subflows and I haven't cound the same log in the last 30 days.

Thanks for any hints on those 2 issues

---

<div class="post-metadata">

**Author:** ![Barbudor](https://avatars.discourse-cdn.com/v4/letter/b/4af34b/32.png) [@Barbudor](https://discourse.nodered.org/u/Barbudor)\
**Post date:** [10 April 2024 07:45 UTC](https://discourse.nodered.org/t/nodered-container-crash-everyday/86933/6 "2024-04-10T07:45:28Z")

</div>

Hello

Anyone with some hints on those 2 errors ?  
The most critical one being the daily crash

Thanks

Jean-Michel

---

<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 April 2024 09:11 UTC](https://discourse.nodered.org/t/nodered-container-crash-everyday/86933/7 "2024-04-10T09:11:19Z")

</div>

> [@Barbudor](#):
>
> using `node.send()`into a promise call back which I'm actually using in a function node:
> 
> ```auto
> // Initialize slack
> const web = new slackWebApi.WebClient("xxxxxxxxxxxxxxxxxxxxxx");
> 
> node.warn(`Slack upload with ${JSON.stringify(msg.payload)}`);
> 
> (async () => {
> const result = await web.files.uploadV2(msg.payload);
> msg.payload = result
> node.send(msg)
> })();
> 
> ```
> 
> If this is to be avoided, could you please advise how I should code that instead ?

The function node is top level async await so this ☝ is unnecessary.

Something like this would be better (added try-catch to show you options available to you in your function nodes)

```auto
// Initialize slack
const web = new slackWebApi.WebClient("xxxxxxxxxxxxxxxxxxxxxx");
node.warn(`Slack upload with ${JSON.stringify(msg.payload)}`);
try {
    const result = await web.files.uploadV2(msg.payload);
    msg.payload = result
    node.send(msg)
} catch (e) {
    node.error(e, msg)
}

```

FWIW: your original code did not have any error handling **inside** the IIFE, so it would **definitely** crash node-red if it failed.

---

<div class="post-metadata">

**Author:** ![Barbudor](https://avatars.discourse-cdn.com/v4/letter/b/4af34b/32.png) [@Barbudor](https://discourse.nodered.org/u/Barbudor)\
**Post date:** [10 April 2024 10:03 UTC](https://discourse.nodered.org/t/nodered-container-crash-everyday/86933/8 "2024-04-10T10:03:06Z")

</div>

Hi @Steve-Mcl

Many thanks. Still a lot to learn 🙂  
Indeed adding error handling code is better

I'll change the code as per your advice and let you know within a couple of days

Best regards

---

<div class="post-metadata">

**Author:** ![Barbudor](https://avatars.discourse-cdn.com/v4/letter/b/4af34b/32.png) [@Barbudor](https://discourse.nodered.org/u/Barbudor)\
**Post date:** [10 April 2024 10:06 UTC](https://discourse.nodered.org/t/nodered-container-crash-everyday/86933/9 "2024-04-10T10:06:03Z")

</div>

Hi @Steve-Mcl

Wouldn't it be required to add a `node.done()` ?

```auto
try {
    const result = await web.files.uploadV2(msg.payload);
    msg.payload = result
    node.send(msg)
    node.done();
} catch (e) {
    node.error(e, msg)
}

```

---

<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 April 2024 10:15 UTC](https://discourse.nodered.org/t/nodered-container-crash-everyday/86933/10 "2024-04-10T10:15:27Z")

</div>

Not really necessary unless you are relying on the `complete` node.

If `node.done()` is excluded, it will still (implicitly) trigger a complete node - however it will be triggered regardless of success (i.e. even node.error is called / node.send not called) when the function node ends cleanly. By adding the explicit `node.done`, you control when the `complete` node is triggered.

In short, `node.send` will send regardless of the inclusion or exclusion of `node.done`

---

<div class="post-metadata">

**Author:** ![Barbudor](https://avatars.discourse-cdn.com/v4/letter/b/4af34b/32.png) [@Barbudor](https://discourse.nodered.org/u/Barbudor)\
**Post date:** [10 April 2024 10:20 UTC](https://discourse.nodered.org/t/nodered-container-crash-everyday/86933/11 "2024-04-10T10:20:31Z")

</div>

Ok, thanks

---

<div class="post-metadata">

**Author:** ![Barbudor](https://avatars.discourse-cdn.com/v4/letter/b/4af34b/32.png) [@Barbudor](https://discourse.nodered.org/u/Barbudor)\
**Post date:** [11 April 2024 17:11 UTC](https://discourse.nodered.org/t/nodered-container-crash-everyday/86933/12 "2024-04-11T17:11:18Z")

</div>

Hi @Steve-Mcl @Colin

I did 2 changes and the crash didn't occurred this morning

1. Remove the async and added the try/catch as suggested by Steve.

2. There was a flow running daily (from one of my colleague) with a function node doing:

```auto
msg.payload = msg.entry.leagues_list;
node.send(msg);
node.done();

msg.payload = msg.entry.teams_list;
node.send(msg);
node.done();

return;

```

I stopped that flow.  
I believe that code is not the best, and may be those 2 x `node.done()` is bad and more likely responsible for the `sendEvent.destination.node.receive is not a function` error message.  
I believe it should be enough to write it like:

```auto
msg.payload = msg.entry.leagues_list;
node.send(msg);
msg.payload = msg.entry.teams_list;
return msg;

```

Do you aggree ?

Thanks

---

<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:** [11 April 2024 17:20 UTC](https://discourse.nodered.org/t/nodered-container-crash-everyday/86933/13 "2024-04-11T17:20:46Z")

</div>

Why do you even need to send 2 messages? The data you want is already present in the msg. Where are you sending these 2 messages that you generate in the function?

as for "better"? No, what you are doing is better suited to a change nodes and wires (that is after all the point of visual programming)

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/9/a9386f42a938438b35dc70e5c76125c5daa52079.png)

the wires branching here ^ will cause the msg to be duplicated, then the change nodes will set your payloads - but i re-iterate, since your values are already in one node, why not just use them?

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/b/6bad4b96110aca0f791858f1577eb966889ad051.png)

---

<div class="post-metadata">

**Author:** ![Barbudor](https://avatars.discourse-cdn.com/v4/letter/b/4af34b/32.png) [@Barbudor](https://discourse.nodered.org/u/Barbudor)\
**Post date:** [11 April 2024 19:49 UTC](https://discourse.nodered.org/t/nodered-container-crash-everyday/86933/14 "2024-04-11T19:49:22Z")

</div>

Thanks @Steve-Mcl  
The visual approach with the 2 changes nodes is definitively the nicest solution

The reason is that there then a split node which create as many messages as elements in both lists.

Another alternative would be to merge both lists into payload and issue a single message to the split node.

"not my flow", I likely would have designed the flow like that anyhow

Thanks again

---

<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:** [10 July 2024 19:50 UTC](https://discourse.nodered.org/t/nodered-container-crash-everyday/86933/15 "2024-07-10T19:50:03Z")

</div>

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