# Node-red crashes consistently (MySQL)

**URL:** <https://discourse.nodered.org/t/node-red-crashes-consistently-mysql/31104>\
**Category:** General\
**Created:** [4 August 2020 03:08 UTC](https://discourse.nodered.org/t/node-red-crashes-consistently-mysql/31104 "2020-08-04T03:08:35Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![reynardlee](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/reynardlee/32/26918_2.png) [@reynardlee](https://discourse.nodered.org/u/reynardlee)\
**Post date:** [4 August 2020 03:08 UTC](https://discourse.nodered.org/t/node-red-crashes-consistently-mysql/31104/1 "2020-08-04T03:08:36Z")

</div>

I was working just fine, yesterday and now there is a problem. It starts normally, but when I select a Date Picker along with two Dropdowns, it seems to stop working. It seems like there's a problem in the MySQL node (it was connected fine). Thanks in advance, a newb here using node-red.

the Date pickers and Dropdowns I mentioned:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/2/1253925bc38cb728a8d26ed275053401421bd30f.png)

node-red logs:

> **[node-red mysql - Pastebin.com](https://pastebin.com/QNiwKxGF)**
>
> Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [4 August 2020 05:17 UTC](https://discourse.nodered.org/t/node-red-crashes-consistently-mysql/31104/2 "2020-08-04T05:17:00Z")

</div>

`FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory`

When you render the chart, how much data are you pushing to it ?

---

<div class="post-metadata">

**Author:** ![reynardlee](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/reynardlee/32/26918_2.png) [@reynardlee](https://discourse.nodered.org/u/reynardlee)\
**Post date:** [4 August 2020 05:32 UTC](https://discourse.nodered.org/t/node-red-crashes-consistently-mysql/31104/3 "2020-08-04T05:32:51Z")

</div>

around 1500 at least 🤣 .

thinking about it, it is quite alot. Is that too much?

---

<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:** [4 August 2020 06:18 UTC](https://discourse.nodered.org/t/node-red-crashes-consistently-mysql/31104/4 "2020-08-04T06:18:30Z")

</div>

Unless your chart is 1500 pixels wide, yes 🙂

---

<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:** [4 August 2020 08:26 UTC](https://discourse.nodered.org/t/node-red-crashes-consistently-mysql/31104/5 "2020-08-04T08:26:37Z")

</div>

> [@reynardlee](#):
>
> Is that too much?

Probably, but it should not be enough to crash it. Could it be that the Join node is outputting intermediate results before you have configured all the inputs? You could add a debug node on the output of the select query function node and then add a two second delay before that is fed to the sql node (to ensure the debug is displayed before the sql node is run, possibly crashing node-red). Then you will be able to see what query is crashing it.

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [4 August 2020 09:22 UTC](https://discourse.nodered.org/t/node-red-crashes-consistently-mysql/31104/6 "2020-08-04T09:22:37Z")

</div>

Well something is blowing memory so either too big a query - or too many queries too fast. but a result set of 1500 "small" objects should be fine. Or maybe something else is filling memory leaving not much for Node-RED

---

<div class="post-metadata">

**Author:** ![reynardlee](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/reynardlee/32/26918_2.png) [@reynardlee](https://discourse.nodered.org/u/reynardlee)\
**Post date:** [4 August 2020 09:59 UTC](https://discourse.nodered.org/t/node-red-crashes-consistently-mysql/31104/7 "2020-08-04T09:59:56Z")

</div>

The Join node will only output results when it receives 3 inputs, so that shouldn't be the problem.

And I was able to display the debug on the output of the Select Query function.  
But nothing displayed at the MySQL debug node until I disconnect it from the Function and Dashboard Chart nodes, it works/debugs just fine.

Seems like it is the function node (which reformats array into an appropriate array for the dashboard chart) right after that caused the crash. As @dceejay pointed out, I think there is too big of a query feeding into the Function node, which caused it to crash.

I went for the approach below but I think, the output from MySQL node is still consider as one msg (a big array), therefore it still doesnt work.

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

I will try to work on reducing the amount of data inputting into the function/chart node, perhaps with a smooth node or rbe node. Do recommend me any other methods, I will try them out!

Thank yall so much for your help! 😁😁 Have a good day ahead.

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [4 August 2020 10:20 UTC](https://discourse.nodered.org/t/node-red-crashes-consistently-mysql/31104/8 "2020-08-04T10:20:46Z")

</div>

yes the mysql node will return a single array. So either you can...  
change the query to be more specific to return a more 'focussed" set of results with just the required data in, and then reformat that smaller amount.  
or  
use a split node to split the array and then filter/reformat each individual result as appropriate.

It seem like you are trying to feed a chart so you can either send it all the data at once (as an array) - or as a timeseries one point at a time - so you can send data with both a payload and timestamp (and maybe topic) properties if you have existing timestamp data in your array. (IE it can handle using the array, or splitting the data if you want to try that approach)

---

<div class="post-metadata">

**Author:** ![reynardlee](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/reynardlee/32/26918_2.png) [@reynardlee](https://discourse.nodered.org/u/reynardlee)\
**Post date:** [5 August 2020 09:58 UTC](https://discourse.nodered.org/t/node-red-crashes-consistently-mysql/31104/9 "2020-08-05T09:58:41Z")

</div>

A funny thing that I discovered/realised today is that, in the For loop of my function node, I wrongly used `i+2` instead of `i++`. I changed nothing else but the i condition for the For loop and it works fine now. There could possibly some contradicting error there when `i+2` that caused it to crash.

It works even when the input array has over 10000 values. 🤣

---

<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:** [5 August 2020 10:10 UTC](https://discourse.nodered.org/t/node-red-crashes-consistently-mysql/31104/10 "2020-08-05T10:10:39Z")

</div>

Were you going off the end of the array? Anything can happen in that case. What did the for loop look like?

---

<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:** [5 August 2020 17:59 UTC](https://discourse.nodered.org/t/node-red-crashes-consistently-mysql/31104/11 "2020-08-05T17:59:39Z")

</div>

> [@reynardlee](#):
>
> in the For loop of my function node, I wrongly used `i+2` instead of `i++`

Was that in the 3rd part like this....

```auto
for(let i = 0; i < someArray.length; i+2) {
  //do a bunch of stuff
}

```

... if so, then I'd go with that being the cause - as `i` will remain `0` for ever & `i+2` was probably less than the `for` break out condition - this results in an infinite loop / eventual crash.

---

<div class="post-metadata">

**Author:** ![reynardlee](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/reynardlee/32/26918_2.png) [@reynardlee](https://discourse.nodered.org/u/reynardlee)\
**Post date:** [6 August 2020 01:37 UTC](https://discourse.nodered.org/t/node-red-crashes-consistently-mysql/31104/12 "2020-08-06T01:37:48Z")

</div>

yes. exactly! The most basic mistake ever.  
`i++` means it will be an increment of +1 every time. Is there a way to have an increment of +2 every time?

edit: I totally forgotten about `i+=2`. That would work perfectly if I am not wrong.

---

<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:** [6 August 2020 05:12 UTC](https://discourse.nodered.org/t/node-red-crashes-consistently-mysql/31104/13 "2020-08-06T05:12:46Z")

</div>

> [@reynardlee](#):
>
> I totally forgotten about `i+=2` . That would work perfectly if I am not wrong

It would work yes, it would step by 2 (skip odd elements)

---

<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:** [6 August 2020 08:28 UTC](https://discourse.nodered.org/t/node-red-crashes-consistently-mysql/31104/14 "2020-08-06T08:28:02Z")

</div>

If you are incrementing by 2 does that mean that at some point in the loop you us `someArray[i+1]`? If you do then in the for statement it should be  
`for(let i = 0; i < someArray.length-1; i+2) {`  
otherwise if the length should somehow be an odd number then you would be indexing off the end of the array.

---

<div class="post-metadata">

**Author:** ![reynardlee](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/reynardlee/32/26918_2.png) [@reynardlee](https://discourse.nodered.org/u/reynardlee)\
**Post date:** [6 August 2020 09:21 UTC](https://discourse.nodered.org/t/node-red-crashes-consistently-mysql/31104/15 "2020-08-06T09:21:28Z")

</div>

Yes, that is right.  
ooh that's true. Thanks for help! much appreciated, loving this friendly community.

---

<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:** [6 August 2020 15:55 UTC](https://discourse.nodered.org/t/node-red-crashes-consistently-mysql/31104/16 "2020-08-06T15:55:46Z")

</div>

> [@Colin](#):
>
> otherwise if the length should somehow be an odd number then you would be indexing off the end of the array.

Speaking from experience I bet (I've done it).

PS, also might be worth mentioning that due to sparse nature of JS arrays, indexing outside the array length will do pretty much nothing except return undefined 🤷‍♂️ (e.g. doesnt blow in ya face up like `c` does)

for example `i` is clearly going out of bounds...

```auto
for (let i = 0; i < 10 ; i++) {
  console.log( [1,2,3,4,5][i] );
}

```

but it keep on rollin' ...

```auto
1
2
3
4
5
undefined
undefined
undefined
undefined
undefined
undefined

```

---

<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:** [20 August 2020 15:55 UTC](https://discourse.nodered.org/t/node-red-crashes-consistently-mysql/31104/17 "2020-08-20T15:55:47Z")

</div>

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