SergiuToporjinschi / node-red-contrib-heater-controller

Heater controller for node-red dashboard
GNU General Public License v3.0
18 stars 17 forks source link

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

Closed akj00 closed 2 years ago

akj00 commented 3 years ago

Hi, I used your great node heater controller, bu now I think I found a bug, or at list a bad behavior. I tested your node with this simple flow:

Img 2020-11-21 085756

Injecting the currentTemp every 5 secs. If you slide for some time you get a crash of the rednode process and the log is at:

==== JS stack trace ========================================= Security context: 0x215cea21 0: builtin exit frame: stringify(this=0x215c65a9 ,0x35740279 ,0x35740279 ,0x2da3375d <JSArray[2]>,0x215c65a9 ) 1: arguments adaptor frame: 1->3 2: tryStringify [0x535ae7b9] [/home/nodered/.node-red/node_modules/socket.io-parser/index.js:~182] [pc=0x2b40ba78](this=0x5c780125 ,0x2da3375d <JSArray[2]>)... FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory nodered.service: Main process exited, code=killed, status=6/ABRT nodered.service: Failed with result 'signal'. nodered.service: Service RestartSec=100ms expired, scheduling restart. nodered.service: Scheduled restart job, restart counter is at 13. Stopped Node-RED graphical event wiring tool. Started Node-RED graphical event wiring tool.

Env: node-red-contrib-heater-controller 2.0.2 node-red v1.2.5 nodejs v12.19.1 npm 6.14.18

I first opened this issue https://github.com/node-red/node-red/issues/2766#issue-747526704

SergiuToporjinschi commented 3 years ago

Hi @akj00, sorry for such long delay. I would need a flow json to test it myself that would be much more east for me. And if you can, would be nice if you can send me also the settings.js, but before, be sure you are removing any sensitive data, like passwords or port IPs etc.

akj00 commented 3 years ago

Hi, I attached the info you required.

settings.js.txt HeaterTestFlow.txt

SergiuToporjinschi commented 3 years ago

Thank you for test data. I will take a look on that, until then, can you try to put the logs max length on 0 ? image I'm thinking if you are sending too many messages each day can get quite big and I see that in settings you have contextStorage in memory

akj00 commented 3 years ago

Hi, Since 21 Nov I upgraded the system and now am running with: nodejs v12.20.1 Node-RED version: v1.2.7 Node.js version: v12.20.1

As you suggested I tested setting "Max Length" to 0, the problem does not arise. Anyway when I put to 1, and I try to slide the temperature up and down after few seconds a have a crash as described in first message.

After this and with "Max Length" set to 1 i configured the contextStorage to localfilesystem

contextStorage: {
   default: {
       module: "localfilesystem"
   }
}

but I had a new crash, the log follows:

1 Feb 08:48:10 - [debug] Flushing localfilesystem context scope 50d83d79.ed7864:e5bda413.c27fd8
1 Feb 08:48:10 - [debug] Flushing localfilesystem context scope global
1 Feb 08:48:40 - [debug] Flushing localfilesystem context scope 50d83d79.ed7864:e5bda413.c27fd8
1 Feb 08:48:40 - [debug] Flushing localfilesystem context scope global
1 Feb 08:49:21 - [debug] Flushing localfilesystem context scope 50d83d79.ed7864:e5bda413.c27fd8
1 Feb 08:49:21 - [debug] Flushing localfilesystem context scope global
<--- Last few GCs --->
[14975:0x2299428]   145278 ms: Mark-sweep 328.2 (347.0) -> 328.1 (347.0) MB, 141.5 / 0.1 ms  (average mu = 0.813, current mu = 0.001) last resort GC in old space requested
[14975:0x2299428]   145419 ms: Mark-sweep 328.1 (347.0) -> 328.0 (347.0) MB, 140.9 / 0.1 ms  (average mu = 0.685, current mu = 0.000) last resort GC in old space requested
<--- JS stacktrace --->
==== JS stack trace =========================================
Security context: 0x3978ea21 <JSObject>
    0: builtin exit frame: byteLength(aka byteLengthUtf8)(this=0x39d5535d <Object map = 0x4a7164cd>,0xa972c659 <Very long string[232981241]>,0x39d5535d <Object map = 0x4a7164cd>)
    1: fromStringFast(aka fromStringFast) [0x39d53afd] [buffer.js:423] [bytecode=0x2bed265d offset=7](this=0x48180279 <undefined>,0xa972c659 <Very long string[232981241]>,0x39d5535d <Object map = 0x4a7164cd>)
    2: fromSt...
FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory
nodered.service: Main process exited, code=killed, status=6/ABRT
nodered.service: Failed with result 'signal'.
nodered.service: Service RestartSec=20s expired, scheduling restart.
nodered.service: Scheduled restart job, restart counter is at 1.
Stopped Node-RED graphical event wiring tool.
Started Node-RED graphical event wiring tool.
1 Feb 08:49:48 - [info]
Welcome to Node-RED
===================
SergiuToporjinschi commented 3 years ago

I was thinking that the logs can cause trouble because it saves some infos and this nod is reacting on currentTemp message if it comes very offen then can be quite long; whats the interval in which currenttemp is sent to heater node, by the way ? it's crazy with so many errors if it works for you and do not need context storage as local let it commented. I'm currently doing a heavy refactoring on this node, I just implemented the unit tests for temperature control, the only things left are messages that are sent from interface (from user actions) to backend plus some minor things and I should be able to release it.

akj00 commented 3 years ago

which currenttemp is sent to heater node, by the way ? In this Test flow as you should see is every 5 secs. But in my IOT project was sent less often, in fact the crash did not come out so quickly. Anyway I will wait for the new release to use again your great Heater node! Thank you for the help

SergiuToporjinschi commented 3 years ago

You will have to wait for a while :(. I can work on this only after "I'm Back from the office" (quotes because I'm working from home ... quarantine.... ) and in the weekends but I'm allocating as much time I can on this.

SergiuToporjinschi commented 2 years ago

Released v3.0, so should not be the case anymore -Requirements for version 3.0.0: -NodeJS: 16.x Minimum version 12.x -node-red: 2.0.6 Minimum version 1.x