in my project folder I run
npm install underscore
the install begins and then it aborts with the following
pi#mserv01:~/foo $ npm install underscore
npm http GET https://registry.npmjs.org/underscore
npm http 304 https://registry.npmjs.org/underscore
npm http GET https://registry.npmjs.org/underscore/-/underscore-1.8.3.tgz
npm http 200 https://registry.npmjs.org/underscore/-/underscore-1.8.3.tgz
abort: +▒▒
▒▒▒\ ▒▒<
==== Stack trace ============================================
Security context: 0x32434659 <JS Object>#0#
1: _parse(aka parse) [/usr/local/lib/node_modules/npm/node_modules/tar/lib/extended-header.js:~61] (this=0x5d74cbad <an ExtendedHeader>#1#,c=0x5d74fca1 <a Buffer>#2#)
2: emit [events.js:95] (this=0x5d74cbad <an ExtendedHeader>#1#,type=0x4dc14839 <String[4]: data>)
3: arguments adaptor frame: 2->1
4: _read [/usr/local/lib/node_modules/npm/node_modules/tar/lib/entry.js:111] (this=0x5d74cbad <an ExtendedHeader>#1#)
8: _read [native v8natives.js:1594] (this=0x5d74cbad <an ExtendedHeader>#1#)
9: write [/usr/local/lib/node_modules/npm/node_modules/tar/lib/entry.js:68] (this=0x5d74cbad <an ExtendedHeader>#1#,c=0x5d74fca1 <a Buffer>#2#)
10: _process [/usr/local/lib/node_modules/npm/node_modules/tar/lib/parse.js:104] (this=0x5d738181 <an Extract>#3#,c=0x5d74fca1 <a Buffer>#2#)
11: /* anonymous */ [/usr/local/lib/node_modules/npm/node_modules/tar/lib/parse.js:46] (this=0x5d738379 <a BlockStream>#4#,c=0x5d74fca1 <a Buffer>#2#)
12: emit [events.js:95] (this=0x5d738379 <a BlockStream>#4#,type=0x4dc14839 <String[4]: data>)
13: arguments adaptor frame: 2->1
14: _emitChunk [/usr/local/lib/node_modules/npm/node_modules/block-stream/block-stream.js:145] (this=0x5d738379 <a BlockStream>#4#,flush=0x32408091 <undefined>)
15: arguments adaptor frame: 0->1
16: resume [/usr/local/lib/node_modules/npm/node_modules/block-stream/block-stream.js:58] (this=0x5d738379 <a BlockStream>#4#)
17: arguments adaptor frame: 1->0
18: resume [/usr/local/lib/node_modules/npm/node_modules/fstream/lib/reader.js:253] (this=0x5d738181 <an Extract>#3#,who=0x5d738181 <an Extract>#3#)
19: arguments adaptor frame: 0->1
20: /* anonymous */ [/usr/local/lib/node_modules/npm/node_modules/tar/lib/parse.js:256] (this=0x5d74486d <an Entry>#5#)
21: emit [events.js:92] (this=0x5d74486d <an Entry>#5#,type=0x4dc164b9 <String[6]: resume>)
22: resume [/usr/local/lib/node_modules/npm/node_modules/tar/lib/entry.js:92] (this=0x5d74486d <an Entry>#5#)
23: resume [/usr/local/lib/node_modules/npm/node_modules/fstream/lib/collect.js:62] (this=0x32434701 <JS Global Object>#6#)
24: unblockEntry [/usr/local/lib/node_modules/npm/node_modules/fstream/lib/collect.js:43] (this=0x32434701 <JS Global Object>#6#)
25: /* anonymous */ [/usr/local/lib/node_modules/npm/node_modules/fstream/lib/collect.js:47] (this=0x5d74486d <an Entry>#5#,dest=0x5d7477c5 <a FileWriter>#7#)
26: /* anonymous */ [/usr/local/lib/node_modules/npm/node_modules/fstream/lib/dir-writer.js:143] (this=0x5d7477c5 <a FileWriter>#7#)
27: emit [events.js:92] (this=0x5d7477c5 <a FileWriter>#7#,type=0x530a276d <String[5]: ready>)
28: /* anonymous */ [/usr/local/lib/node_modules/npm/node_modules/fstream/lib/file-writer.js:45] (this=0x5d74a615 <a WriteStream>#8#,fd=10)
29: emit [events.js:95] (this=0x5d74a615 <a WriteStream>#8#,type=0x4dc1f615 <String[4]: open>)
30: arguments adaptor frame: 2->1
31: /* anonymous */ [fs.js:1662] (this=0x5d74a615 <a WriteStream>#8#,er=0x32408081 <null>,fd=10)
35: /* anonymous */(aka /* anonymous */) [native v8natives.js:1597] (this=0x32408091 <undefined>)
36: arguments adaptor frame: 2->0
37: done [/usr/local/lib/node_modules/npm/node_modules/graceful-fs/graceful-fs.js:144] (this=0x5d74a9e5 <an OpenReq>#9#,er=0x32408081 <null>,result=10)
38: done [/usr/local/lib/node_modules/npm/node_modules/graceful-fs/graceful-fs.js:64] (this=0x5d74a9e5 <an OpenReq>#9#,er=0x32408081 <null>,fd=10)
42: /* anonymous */ [native v8natives.js:1597] (this=0x32408081 <null>)
43: arguments adaptor frame: 2->0
45: oncomplete [fs.js:107] (this=0x5d74ab99 <an Object>#10#)
46: arguments adaptor frame: 2->0
... MORE STACKTRACE... TOO MUCH TO PASTE IT ALL HERE ...
0: 0x5d746321 <JS Function onend>#98#
1: 0x5d74b521 <JS Function cleanup>#99#
#83# 0x3063fd3d: 0x3063fd3d <JS Function>
#84# 0x5d74a6f1: 0x5d74a6f1 <JS Array[0]>
#85# 0x5d74abcd: 0x5d74abcd <JS Function g>
listener: 0x44f2c41d <JS Function>#100#
#86# 0x5d739b91: 0x5d739b91 <JS Function>
#87# 0x5d734891: 0x5d734891 <JS Function extractEntry>
#88# 0x5d73da4d: 0x5d73da4d <JS Function>
#89# 0x5d73a279: 0x5d73a279 <JS Function onerror>
#90# 0x5d73a93d: 0x5d73a93d <JS Function>
#91# 0x5d73dba5: 0x5d73dba5 <JS Function onerror>
#92# 0x5d73a575: 0x5d73a575 <JS Function g>
listener: 0x5d73a29d <JS Function onclose>#101#
#93# 0x5d73486d: 0x5d73486d <JS Function cb>
#94# 0x5d73dbc9: 0x5d73dbc9 <JS Function cleanup>
#95# 0x5d73de1d: 0x5d73de1d <JS Array[2]>
0: 0x5d73a161 <JS Function>#102#
1: 0x5d73dbc9 <JS Function cleanup>#94#
#96# 0x5d748861: 0x5d748861 <JS Function>
#97# 0x5d74b4fd: 0x5d74b4fd <JS Function onerror>
#98# 0x5d746321: 0x5d746321 <JS Function onend>
#99# 0x5d74b521: 0x5d74b521 <JS Function cleanup>
#100# 0x44f2c41d: 0x44f2c41d <JS Function>
#101# 0x5d73a29d: 0x5d73a29d <JS Function onclose>
#102# 0x5d73a161: 0x5d73a161 <JS Function>
=====================
Trace/breakpoint trap
It won't let me paste the entire stack trace, but this is what is happening. Any ideas what might be going on... other modules are installing fine.
Related
I am running into a memory issue when building using Vite:
Reached heap limit Allocation failed - JavaScript heap out of memory
This is the output:
<--- Last few GCs --->
[23466:0x5e196b0] 37408 ms: Mark-sweep (reduce) 489.9 (502.1) -> 488.2 (501.6) MB, 1271.9 / 0.0 ms (+ 3.8 ms in 6 steps since start of marking, biggest step 1.3 ms, walltime since start of marking 1318 ms) (average mu = 0.368, current mu = 0.040) allo[23466:0x5e196b0] 38726 ms: Mark-sweep (reduce) 490.5 (503.2) -> 489.9 (503.1) MB, 1315.0 / 0.0 ms (average mu = 0.220, current mu = 0.002) allocation failure GC in old space requested
<--- JS stacktrace --->
FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory
1: 0xb06730 node::Abort() [node]
2: 0xa1b6d0 [node]
3: 0xce1dd0 v8::Utils::ReportOOMFailure(v8::internal::Isolate*, char const*, bool) [node]
4: 0xce2177 v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, bool) [node]
5: 0xe997e5 [node]
6: 0xea94ad v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags) [node]
7: 0xeac1ae v8::internal::Heap::AllocateRawWithRetryOrFailSlowPath(int, v8::internal::AllocationType, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) [node]
8: 0xe6d6ea v8::internal::Factory::NewFillerObject(int, bool, v8::internal::AllocationType, v8::internal::AllocationOrigin) [node]
9: 0x11e658c v8::internal::Runtime_AllocateInOldGeneration(int, unsigned long*, v8::internal::Isolate*) [node]
10: 0x15da0d9 [node]
Aborted (core dumped)
Below is my vite.config.js file:
import { defineConfig } from "vite";
import laravel from "laravel-vite-plugin";
import vue from "#vitejs/plugin-vue";
import Components from "unplugin-vue-components/vite";
import { PrimeVueResolver } from "unplugin-vue-components/resolvers";
export default defineConfig({
plugins: [
Components({
resolvers: [PrimeVueResolver()]
}),
laravel({
input: "resources/js/app.js",
refresh: true
}),
vue({
template: {
transformAssetUrls: {
base: null,
includeAbsolute: false
}
}
})
]
});
The problem seems related to the unplugin-vue-components package. If I remove the below from the config file, it works:
Components({
resolvers: [PrimeVueResolver()]
}),
This problem seems to be closely related to this open issue on the Vite repository on Github: https://github.com/vitejs/vite/issues/2433
I'm experiencing the exact same problem on a React/Vite config.
Here it's the output :
<--- Last few GCs --->
[41:0x5613e40] 4819 ms: Mark-sweep 252.8 (258.5) -> 252.4 (259.2) MB, 131.3 / 0.0 ms (average mu = 0.387, current mu = 0.117) allocation failure; scavenge might not succeed
<--- JS stacktrace --->
FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory
1: 0xb6b850 node::Abort() [/usr/bin/node]
2: 0xa806a6 [/usr/bin/node]
3: 0xd52140 v8::Utils::ReportOOMFailure(v8::internal::Isolate*, char const*, bool) [/usr/bin/node]
4: 0xd524e7 v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, bool) [/usr/bin/node]
5: 0xf2fbe5 [/usr/bin/node]
6: 0xf420cd v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags) [/usr/bin/node]
7: 0xf1c7ce v8::internal::HeapAllocator::AllocateRawWithLightRetrySlowPath(int, v8::internal::AllocationType, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) [/usr/bin/node]
8: 0xf1db97 v8::internal::HeapAllocator::AllocateRawWithRetryOrFailSlowPath(int, v8::internal::AllocationType, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) [/usr/bin/node]
9: 0xefed6a v8::internal::Factory::NewFillerObject(int, v8::internal::AllocationAlignment, v8::internal::AllocationType, v8::internal::AllocationOrigin) [/usr/bin/node]
10: 0x12c265f v8::internal::Runtime_AllocateInYoungGeneration(int, unsigned long*, v8::internal::Isolate*) [/usr/bin/node]
11: 0x16ef479 [/usr/bin/node]
Aborted
And here it's my Vite config :
import react from '#vitejs/plugin-react';
import path from 'node:path';
import { defineConfig } from 'vite';
import dts from 'vite-plugin-dts';
export default defineConfig({
plugins: [
react({
jsxRuntime: 'classic',
}),
dts({
insertTypesEntry: true,
}),
],
envPrefix: 'SPA_',
build: {
sourcemap: true,
lib: {
entry: path.resolve(__dirname, 'src/index.ts'),
name: 'Spa',
formats: ['es', 'umd'],
fileName: (format) => `spa.${format}.js`,
},
rollupOptions: {
external: ['react', 'react-dom'],
output: {
globals: {
react: 'React',
'react-dom': 'ReactDOM',
},
},
},
},
});
Have you been able to work through it?
I have a NestJS/Node.js application using socket.io for websocket communication. In this particular case, while trying to send a BufferArray content nearly as big as 1MB, our server (with 500MB of RAM limit) crashes. Why is the socket connection demanding so much memory if the "file" being sent is just 1MB big?
This is the section of the app that listens for a ws command coming from the client and sends the content back:
#SubscribeMessage('report')
async listenToReportRequests(
#MessageBody() data: any,
#ConnectedSocket() client: Socket
) {
console.log('Received report request');
const params = data['0'];
const reportType = data['1'];
const timezone = data['2'];
const report = await this.analyticsService.getExcelReport(
params as IExcelReportOptions,
reportType as EExcelType,
timezone,
);
console.log('Finished generating the report', report.byteLength);
client.emit('sendReport', report);
console.log('Emitted report');
}
The crash log is shown as:
<--- Last few GCs --->
[124:0x53f0d40] 78114918 ms: Mark-sweep (reduce) 251.5 (258.0) -> 248.1 (255.3) MB, 1204.1 / 0.0 ms (average mu = 0.147, current mu = 0.014) allocation failure scavenge might
not succeed
[124:0x53f0d40] 78116398 ms: Mark-sweep (reduce) 251.3 (257.5) -> 249.2 (256.3) MB, 1476.4 / 0.0 ms (average mu = 0.075, current mu = 0.003) allocation failure scavenge might
not succeed
<--- JS stacktrace --->
FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
1: 0xa3aaf0 node::Abort() [node]
2: 0x970199 node::FatalError(char const*, char const*) [node]
3: 0xbba45e v8::Utils::ReportOOMFailure(v8::internal::Isolate*, char const*, bool) [nodal::Isolate*, char const*, bool) [node]
5: 0xd769e5 [node]
6: 0xd7756f [node]
7: 0xd853ab v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags) [node]
8: 0xd88f6c v8::internal::Heap::AllocateRawWithRetryOrFailSlowPath(int, v8::internal::AllocationType, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) [node]
9: 0xd5764b v8::internal::Factory::NewFillerObject(int, bool, v8::internal::AllocationType, v8::internal::AllocationOrigin) [node]
10: 0x109fc0f v8::internal::Runtime_AllocateInYoungGeneration(int, unsigned long*, v8::internal::Isolate*) [node]
11: 0x1448e19 [node]
Aborted (core dumped)
The Node.js version used is 14-slim and the socket libraries' versions are
"#types/socket.io": "^2.1.4",
"#nestjs/platform-socket.io": "^7.6.13",
"#nestjs/websockets": "^7.6.13",
Thank you very much in advance!
I have this little script to dump a bunch of text data from a source to disk in the form of gzip. Most sources I pull from work without issue, but I've come up against one which is throwing JavaScript heap out of memory.
Here's a snippet of what it's doing
const fs = require('fs');
const zlib = require('zlib');
const file = fs.createWriteStream('file.gz');
const gzip = zlib.createGzip();
gzip.pipe(file);
// ... code to connect to someDataSource would be here
someDataSource.on('data', (line) => { // feeding lines of text
gzip.write(line);
});
someDataSource.on('done', () => {
// crashes before this point
gzip.end();
});
I suspect the zlib module is buffering way more than it should before flushing to disk. At the time of the crash the gz file is only about 4MB large. Like I said above other data sources I pull from work, and all of those produce gz files well over 50MB.
The docs on the module are here: https://nodejs.org/api/zlib.html#zlib_class_options
I'm not sure how to tweak the options to get this to behave.
CRASH:
<--- Last few GCs --->
[33692:0x10264e000] 97556 ms: Scavenge 1370.6 (1411.7) -> 1363.3 (1412.2) MB, 4.5 / 0.0 ms (average mu = 0.174, current mu = 0.137) allocation failure
[33692:0x10264e000] 97569 ms: Scavenge 1371.0 (1412.2) -> 1363.7 (1413.7) MB, 4.5 / 0.0 ms (average mu = 0.174, current mu = 0.137) allocation failure
[33692:0x10264e000] 97582 ms: Scavenge 1371.3 (1413.7) -> 1364.0 (1430.2) MB, 4.5 / 0.0 ms (average mu = 0.174, current mu = 0.137) allocation failure
<--- JS stacktrace --->
==== JS stack trace =========================================
0: ExitFrame [pc: 0xdd88f3dbe3d]
Security context: 0x32b80cc1e6e9 <JSObject>
1: /* anonymous */(aka /* anonymous */) [0x32b897904941] [/some/path/node_modules/tedious/lib/token/stream-parser.js:~154] [pc=0xdd88f6fbec4](this=0x32b8101826f1 <undefined>)
2: valueParse(aka valueParse) [0x32b8c73a8ab9] [/some/path/node_modules/tedious/lib/value-parser.js:~74] [pc=0xdd88f6c96d3](this=0x32b8101826f1 ...
FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
1: 0x10003c597 node::Abort() [/usr/local/bin/node]
2: 0x10003c7a1 node::OnFatalError(char const*, char const*) [/usr/local/bin/node]
3: 0x1001ad575 v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, bool) [/usr/local/bin/node]
4: 0x100579242 v8::internal::Heap::FatalProcessOutOfMemory(char const*) [/usr/local/bin/node]
5: 0x10057bd15 v8::internal::Heap::CheckIneffectiveMarkCompact(unsigned long, double) [/usr/local/bin/node]
6: 0x100577bbf v8::internal::Heap::PerformGarbageCollection(v8::internal::GarbageCollector, v8::GCCallbackFlags) [/usr/local/bin/node]
7: 0x100575d94 v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags) [/usr/local/bin/node]
8: 0x100574998 v8::internal::Heap::HandleGCRequest() [/usr/local/bin/node]
9: 0x10052a1c8 v8::internal::StackGuard::HandleInterrupts() [/usr/local/bin/node]
10: 0x1007d9bb1 v8::internal::Runtime_StackGuard(int, v8::internal::Object**, v8::internal::Isolate*) [/usr/local/bin/node]
11: 0xdd88f3dbe3d
12: 0xdd88f6fbec4
13: 0xdd88f6c96d3
14: 0xdd88f6c8870
[1] 33692 abort node app.js
add a drain eventlistener. Because writing data to bootstrap is a synchronous behaviour.
someDataSource.on('data', (line) => { // feeding lines of text
const ok = gzip.write(line);
if(!ok) {
someDataSource.pause();
}
});
gzip.on('drain', () => {
someDataSource.resume();
});
someDataSource.on('done', () => {
// crashes before this point
gzip.end();
});
or use pipe method directly.
someDataSource.pipe(gzip).pipe(file);
You can also try to increase the memory allocated to Node.js:
node --max-old-space-size=8192 your_script.js
After a lot of postMessages to a webworker I get an abort and stacktrace as shown below in my original question.
I decreased the interval from 250ms to 6ms and then this problem appears earlier in time, about 45min instead of 6-9 hours.
The code is rather simple
mainapp.js
const Worker = require('webworker-threads').Worker;
var myappwebworker = new Worker('./myappwebworker.js');
myappwebworker.addEventListener('message', function(e) {
console.log(e)
});
setInterval(function() {
myappwebworker.postMessage('hello');
}, 250); // or 5 for abort in about 45min
myappwebworker.js
self.addEventListener('message', function(e) {
self.postMessage('You said: ' + e.data);
}, false);
What is the reason for this? Do I run out of heap because the garbage collector don't have time to run or something similar? In any case what can be done to prevent this?
This was the original question until I updated based on my findings
Title:nodejs webworker-threads debugging, where to start?
If I get this kind of stack traces after 7-8 hours of running my nodejs app, how do I start to debug this to find the culprit in my code?
node[3836]: ../src/node_platform.cc:414:std::shared_ptr<node::PerIsolatePlatformData> node::NodePlatform::ForIsolate(v8::Isolate*): Assertion `data' failed.
1: 0x8dc510 node::Abort() [node]
2: 0x8dc5e5 [node]
3: 0x965687 node::NodePlatform::CallOnForegroundThread(v8::Isolate*, v8::Task*) [node]
4: 0xeda2ab v8::internal::IncrementalMarking::Start(v8::internal::GarbageCollectionReason) [node]
5: 0xed4b6c v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags) [node]
6: 0xed7371 v8::internal::Heap::AllocateRawWithRetryOrFail(int, v8::internal::AllocationSpace, v8::internal::AllocationAlignment) [node]
7: 0xeac650 [node]
8: 0xeac6e7 v8::internal::Factory::NewJSObject(v8::internal::Handle<v8::internal::JSFunction>, v8::internal::PretenureFlag) [node]
9: 0xae84ae v8::Object::New(v8::Isolate*) [node]
10: 0x7ff7eb5f0913 BSONDeserializer::DeserializeDocumentInternal(bool) [/home/ubuntu/myapp/node_modules/webworker-threads/build/Release/WebWorkerThreads.node]
11: 0x7ff7eb5f0b97 BSONDeserializer::DeserializeDocument(bool) [/home/ubuntu/myapp/node_modules/webworker-threads/build/Release/WebWorkerThreads.node]
12: 0x7ff7eb5f0f40 BSONDeserializer::DeserializeValue(BsonType, bool) [/home/ubuntu/myapp/node_modules/webworker-threads/build/Release/WebWorkerThreads.node]
13: 0x7ff7eb5f0946 BSONDeserializer::DeserializeDocumentInternal(bool) [/home/ubuntu/myapp/node_modules/webworker-threads/build/Release/WebWorkerThreads.node]
14: 0x7ff7eb5f0b97 BSONDeserializer::DeserializeDocument(bool) [/home/ubuntu/myapp/node_modules/webworker-threads/build/Release/WebWorkerThreads.node]
15: 0x7ff7eb5f3bcf [/home/ubuntu/myapp/node_modules/webworker-threads/build/Release/WebWorkerThreads.node]
16: 0x7ff7eb5f4519 [/home/ubuntu/myapp/node_modules/webworker-threads/build/Release/WebWorkerThreads.node]
17: 0x7ff7f25536ba [/lib/x86_64-linux-gnu/libpthread.so.0]
18: 0x7ff7f228941d clone [/lib/x86_64-linux-gnu/libc.so.6]
Here is a similar stack trace
1: 0x8dc510 node::Abort() [node]
2: 0x8dc5e5 [node]
3: 0x965687 node::NodePlatform::CallOnForegroundThread(v8::Isolate*, v8::Task*) [node]
4: 0xeda2ab v8::internal::IncrementalMarking::Start(v8::internal::GarbageCollectionReason) [node]
5: 0xed4b6c v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags) [node]
6: 0xed7371 v8::internal::Heap::AllocateRawWithRetryOrFail(int, v8::internal::AllocationSpace, v8::internal::AllocationAlignment) [node]
7: 0xe9f655 [node]
8: 0xea6eca v8::internal::Factory::NewRawOneByteString(int, v8::internal::PretenureFlag) [node]
9: 0xea71db v8::internal::Factory::NewStringFromOneByte(v8::internal::Vector<unsigned char const>, v8::internal::PretenureFlag) [node]
10: 0xea7c2d v8::internal::Factory::NewStringFromUtf8(v8::internal::Vector<char const>, v8::internal::PretenureFlag) [node]
11: 0xae7ba9 v8::String::NewFromUtf8(v8::Isolate*, char const*, v8::NewStringType, int) [node]
12: 0x7fa4984eda83 Nan::imp::Factory<v8::String>::return_t Nan::New<v8::String, char*>(char*) [/home/ubuntu/myapp/node_modules/webworker-threads/build/Release/WebWorkerThreads.node]
13: 0x7fa4984e82ab BSON::BSON() [/home/ubuntu/myapp/node_modules/webworker-threads/build/Release/WebWorkerThreads.node]
14: 0x7fa4984e9b9e [/home/ubuntu/myapp/node_modules/webworker-threads/build/Release/WebWorkerThreads.node]
15: 0x7fa4984ea519 [/home/ubuntu/myapp/node_modules/webworker-threads/build/Release/WebWorkerThreads.node]
16: 0x7fa49c2cd6ba [/lib/x86_64-linux-gnu/libpthread.so.0]
17: 0x7fa49c00341d clone [/lib/x86_64-linux-gnu/libc.so.6]
There are messages posted at least 4 times a second to the webworker and the code
The webworker is set up in this fashion
const Worker = require('webworker-threads').Worker;
mywebworker = new Worker('./myappwebworker.js');
setInterval(function() {
mywebworker.postMessage('hello');
}, 250);
Other events also trigger messages to the worker. The system is Ubuntu 16.04 and node V10.15.3
In node what is the best method to find the problem causing this?
Two things come to mind.
If you leave the debug window open, depending on the application, trash collection can be halted, causing this kind of issue. Caught me out several times with hard working processes such as video through OpenCV.
setInterval() I believe, won't care if the inner-code is executed or is blocking (That is, blocking when it shouldn't be or blocking too long).
If blocked for more than 250ms, you'll be building up the stack.
Perhaps this kind of code will give you a better debugging experience, if postMessage halts, you'll not build up stack:
function doIt() {
mywebworker.postMessage('hello');
setTimeout(function() {
doIt();
},250);
}
doIt();
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)
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/');
});
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