Skip to content

Commit 94f45be

Browse files
committed
3.0.0
- Add 15 and 16 to Travis - Updated CHANGELOG.md and README.md - Removed `GC_MONITORING` as option and `gc-stats` with it
1 parent 513a6d4 commit 94f45be

File tree

7 files changed

+15
-1036
lines changed

7 files changed

+15
-1036
lines changed

.travis.yml

+2
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,6 @@ node_js:
88
- "12"
99
- "13"
1010
- "14"
11+
- "15"
12+
- "16"
1113
script: npm run dummy

CHANGELOG.md

+7
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
10-02-2022 Paul Rütter
2+
- 3.0.0
3+
- Added Node 16 support (by merging https://github.com/blueconic/node-oom-heapdump/pull/20, Thanks Simon Abbott!).
4+
This fixes a recursion issue.
5+
- Removed "GC_MONITORING" at it relied on `gc-stats`, which is no longer maintained (and contained security issues)
6+
- Updated `node-pre-gyp` to `@mapbox/node-pre-gyp` so security issues are mitigated
7+
18
12-10-2020 Paul Rütter
29
- 2.1.0
310
- Added Node 14 support

README.md

+2-7
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Node module which will create a V8 heap snapshot right before an "Out of Memory"
55

66
It can also create heapdumps and CPU profiles on request like 'v8-profiler', but does this off-process so it doesn't interfere with execution of the main process.
77

8-
Tested on Node.js 7.x, 8.x, 9.x, 10.x, 11.x, 12.x, 13.x and 14.x.
8+
Tested on Node.js 7.x, 8.x, 9.x, 10.x, 11.x, 12.x, 13.x, 14.x, 15.x and 16.x.
99
No support for Node.js < 7.0 at the moment (although this can be fixed if needed).
1010

1111
Also comes with prebuilt binaries (hosted on Github releases), thanks to Stuart Miller (https://github.com/spmiller).
@@ -63,17 +63,12 @@ On Node.js 12.x the latter two flags seem to cause some stability issues (see ht
6363

6464
# Options
6565
* heapdumpOnOOM - boolean whether to create a heapdump when an out of memory occurs. Default true.
66-
* OOMImplementation - Either "NATIVE_HOOK" or "GC_MONITORING".
66+
* OOMImplementation - Only "NATIVE_HOOK" is supported starting from 3.0.0
6767
"NATIVE_HOOK" relies on the native v8 hook and makes sure that the heapdump is actually created when the OoM occurs. It's more impacted by the OoMKiller of Unix systems though, when being run in memory restricted environments like Docker.
68-
"GC_MONITORING" is the old implementation, which relies on GC monitoring. It's less impacted by OoMKiller, because the 'threshold' parameter determines when to create the heapdump. Use this option when you run into the OoMKiller of the Unix OS. Default is "NATIVE_HOOK".
6968
* path - the path where the heapdump ends up when an out of memory error occurs. '.heapsnapshot' is automatically appended. Defaults to this modules' directory.
7069
* addTimestamp - add a timestamp to the out of memory heapdump filename, to make it unique. Default is false.
7170
* port - optionally, the alternative DevTools protocol port. Defaults to 9229. Should map on the port given to the --inspect arg.
7271

73-
The following options are only relevant when OOMImplementation="GC_MONITORING".
74-
* limit - optionally, specify a limit to how many heapdumps will be created when being above the threshold. Default is 3.
75-
* threshold - integer between 0 and 100 (%) which determines when to make the heapdump. When the used heapSize exceeds the threshold, a heapdump is made. This value can be tuned depending on your configuration; if memory usage is very volatile, a lower value might make more sense. Default is 70.
76-
7772
# API
7873
Besides creating heapdumps when an out of memory error occurs, there also is an API for creating heapdumps and CPU profiles on request. See below for the currently available API.
7974

index.js

+1-12
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,8 @@ function parseOptions(options) {
8484
if (options.heapdumpOnOOM === undefined) {
8585
options.heapdumpOnOOM = true;
8686
}
87-
if (options.OOMImplementation === undefined){
87+
if (options.OOMImplementation === undefined) {
8888
// default is the "new" implementation
89-
// the other option is "GC_MONITORING", which is the old implementation (which is less impacted by OoMKiller)
9089
options.OOMImplementation = "NATIVE_HOOK";
9190
}
9291
if (options.port === undefined) {
@@ -97,16 +96,6 @@ function parseOptions(options) {
9796
if (options.path === undefined) {
9897
options.path = "OoM-pid-" + process.pid;
9998
}
100-
if (options.limit === undefined) {
101-
options.limit = 3;
102-
} else {
103-
options.limit = parseInt(options.limit);
104-
}
105-
if (options.threshold === undefined) {
106-
options.threshold = 70;
107-
} else {
108-
options.threshold = parseInt(options.threshold);
109-
}
11099
if (options.addTimestamp === undefined) {
111100
options.addTimestamp = false;
112101
} else {

lib/index.js

-34
Original file line numberDiff line numberDiff line change
@@ -8,48 +8,14 @@ class NodeOomHeapDumpImpl {
88
this._files = [];
99
this._busy = false;
1010
this._count = 0;
11-
this._limitReached = false;
1211

1312
if (this._opts.heapdumpOnOOM) {
1413
if (options.OOMImplementation === "NATIVE_HOOK") {
1514
require('bindings')('node_oom_heapdump_native.node').call(this._getHeapSnapshotPath(this._opts.path), this._opts.addTimestamp);
16-
} else if (options.OOMImplementation === "GC_MONITORING") {
17-
this._monitorHeap();
1815
}
1916
}
2017
}
2118

22-
_monitorHeap() {
23-
// see https://www.npmjs.com/package/gc-stats
24-
let gcStats = new require('gc-stats')();
25-
gcStats.on('stats', (stats) => {
26-
// gctype 2 is a Full GC (Mark/Sweep/Compact)
27-
if (stats.gctype === 2 && !this._busy) {
28-
let memoryUsagePercentage = Math.round((stats.after.usedHeapSize / stats.after.heapSizeLimit) * 100);
29-
if (memoryUsagePercentage > this._opts.threshold) {
30-
if (this._count < this._opts.limit) {
31-
// this is a full GC and the used heap size is using more than x% of the assigned heap space limit
32-
console.warn('OoM is imminent: Full GC (Mark/Sweep/Compact) complete and still more than %s% (%s%) of the heap is used. Creating heapdump now. GC stats: ', this._opts.threshold, Math.round(memoryUsagePercentage), JSON.stringify(stats));
33-
34-
this.createHeapSnapshot(this._opts.path, "OoM");
35-
36-
// block execution of other code for a while (5 second) to enable snapshot to be created
37-
const time = Date.now();
38-
let diff = 0;
39-
do {
40-
diff = Date.now() - time;
41-
}
42-
while (diff < 5000);
43-
} else if (!this._limitReached) {
44-
this._limitReached = true;
45-
console.warn("OoM heapdump limit reached (%s); no more heapdumps will be created.", this._opts.limit);
46-
return;
47-
}
48-
}
49-
}
50-
});
51-
}
52-
5319

5420
/**
5521
* Calls the designated worker and returns a promise

0 commit comments

Comments
 (0)