-1

My Node.JS script responds with this error:

error: Forever detected script was killed by signal: SIGKILL error: Script restart attempt #15

Last few GCs:

[11266:0x2890040] 75587 ms: Mark-sweep 1363.8 (1424.5) -> 1363.5 (1423.5) MB, 1341.2 / 4.2 ms (average mu = 0.168, current mu = 0.119) allocation failure scavenge might not succeed [11266:0x2890040] 75605 ms: Scavenge 1364.1 (1423.5) -> 1363.8 (1424.0) MB, 11.4 / 0.0 ms (average mu = 0.168, current mu = 0.119) allocation failure [11266:0x2890040] 75621 ms: Scavenge 1364.4 (1424.0) -> 1364.2 (1425.0) MB, 10.6 / 0.0 ms (average mu = 0.168, current mu = 0.119) allocation failure

JS stacktrace

==== JS stack trace =========================================

0: ExitFrame [pc: 0x2b010e34fb5d]
1: StubFrame [pc: 0x2b010e350eca]
Security context: 0x17ee2c91d969 2: normalizeString(aka normalizeString) [0x47fafaaaf01] [path.js:~57] [pc=0x2b010e58d424](this=0x2202476025b1 ,0x3086a38e3169 ,0x220247602801 ,0x10ca23627b19 ,0x047fafaaaf41 ) 3: /* anonymous */(aka...

FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory 1: 0x90af00 node::Abort() [node] 2: 0x90af4c [node] 3: 0xb05f9e v8::Utils::ReportOOMFailure(v8::internal::Isolate*, char const*, bool) [node] 4: 0xb061d4 v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, bool) [node] 5: 0xf0c6f2 [node] 6: 0xf0c7f8 v8::internal::Heap::CheckIneffectiveMarkCompact(unsigned long, double) [node] 7: 0xf18f88 v8::internal::Heap::PerformGarbageCollection(v8::internal::GarbageCollector, v8::GCCallbackFlags) [node] 8: 0xf19b1b v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags) [node] 9: 0xf1c851 v8::internal::Heap::AllocateRawWithRetryOrFail(int, v8::internal::AllocationSpace, v8::internal::AllocationAlignment) [node] 10: 0xee6834 v8::internal::Factory::NewFillerObject(int, bool, v8::internal::AllocationSpace) [node] 11: 0x11a0672 v8::internal::Runtime_AllocateInNewSpace(int, v8::internal::Object**, v8::internal::Isolate*) [node] 12: 0x2b010e34fb5d Aborted (core dumped)
Jack
  • 1,453
  • 1
  • 15
  • 35
  • 1
    Perhaps you can show the code that causes this error? Also see this question: https://stackoverflow.com/questions/38558989/node-js-heap-out-of-memory – Jonathan Nov 02 '18 at 15:26

2 Answers2

0
let express = require('express');
let app = express();
let server = require('http').Server(app);
let io = require('socket.io')(server);
class MyEmitter extends EventEmitter {}
const emitter = new MyEmitter();
emitter.setMaxListeners(emitter.getMaxListeners() + 1);
emitter.once('event', () => {
    // do stuff
    emitter.setMaxListeners(Math.max(emitter.getMaxListeners() - 1, 0));
});
app.use(express.static('public'));
app.get('/send', function(req, res) {
    res.status(200).send('hola mundo!');
});
let sms = [];
io.on('connection', function(socket) {
    console.log('alguien se a conectado con sockets');
    socket.on('newMessage', function(data) {
        sms.push(data);
        io.sockets.emit('messages', sms);
    });
    socket.on('UserRes', function(data) {
        io.sockets.emit('UserRespnse', data);
    });
    socket.on('detectUser', function(data) {
        io.sockets.emit('user', data);
    });
    socket.on('admin_notification', function(data) {
        io.sockets.emit('admin_notification', data);
    });
});
server.listen('3000', function() {
    console.log('servidor corriendo en http://localhost:3000/');
});
0

Two possible reasons for this FATAL ERROR to occur

  • Either you are pushing data in each iteration of an infinite loop, after few seconds as it reaches the memory space, the server crashes and this error is shown. So, You need to check your code for this error.
  • Or you are if you are really working with huge datasets and the dataset is already of size more than standard limit of file size a node script can handle then you can use the following command to overwrite the default memory size handled by node script.

    node --max-old-space-size=myFileSize myFile.js
    

    example

    node --max-old-space-size=4096 myFile.js
    
d1fficult
  • 931
  • 8
  • 18