Socket
Socket
Sign inDemoInstall

node-oom-heapdump

Package Overview
Dependencies
20
Maintainers
1
Versions
42
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.0.6 to 1.0.7

5

index.js

@@ -72,2 +72,7 @@ let nodeOomLib = require("./lib");

}
if (options.addTimestamp === undefined) {
options.addTimestamp = false;
} else {
options.addTimestamp = options.addTimestamp === true;
}
}

4

lib/heapdumpWorker.js

@@ -23,2 +23,6 @@ let fs = require('fs');

let writeStream = fs.createWriteStream(path);
writeStream.on('error', (err) => {
console.error("Heapdump path not valid or writable", err);
process.exit(-1);
});

@@ -25,0 +29,0 @@ debugInstance.on('HeapProfiler.addHeapSnapshotChunk', function (evt) {

28

lib/index.js

@@ -31,3 +31,3 @@ let cp = require("child_process");

this.createHeapSnapshot(path.resolve('./' + this._opts.path + '.heapsnapshot'), "OoM");
this.createHeapSnapshot(this._opts.path, "OoM");

@@ -58,2 +58,19 @@ // block execution of other code for a while (5 second) to enable snapshot to be created

createHeapSnapshot(snapshotPath, logPrefix) {
if (!snapshotPath) {
snapshotPath = path.resolve(__dirname, "./heapsnapshot");
}
if (logPrefix === "OoM" && this._opts.addTimestamp){
if (snapshotPath.endsWith(".heapsnapshot")) {
snapshotPath = snapshotPath.replace(".heapsnapshot", "");
}
// in case of OoM error, add if timestamp if needed
snapshotPath += "-" + Date.now();
}
if (!snapshotPath.endsWith(".heapsnapshot")) {
snapshotPath += ".heapsnapshot";
}
// resolve to absolute file path
snapshotPath = path.resolve(snapshotPath);
// start OoMworker to create heapdump

@@ -69,11 +86,2 @@ let child = cp.spawn('node', [path.resolve(__dirname, './heapdumpWorker.js'), this._opts.port, snapshotPath, logPrefix || ""], {

if (!snapshotPath) {
snapshotPath = path.resolve(__dirname, "./heapsnapshot-" + Date.now());
}
if (!snapshotPath.endsWith(".heapsnapshot")) {
snapshotPath = snapshotPath + ".heapsnapshot";
}
// resolve to absolute file path
snapshotPath = path.resolve(snapshotPath);
child.on('error', (err) => {

@@ -80,0 +88,0 @@ error = err;

{
"name": "node-oom-heapdump",
"version": "1.0.6",
"version": "1.0.7",
"description": "Create a V8 heap snapshot right before an \"Out of Memory\" error occurs, or create a heap snapshot on request.",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -20,3 +20,3 @@ # node-oom-heapdump

# Example
Just run "npm test" to see it in action. It creates a heapdump named "my_snapshot.heapsnapshot" in the root.
Just run "npm test" to see it in action. It creates a heapdump named "my_heapdump.heapsnapshot" in the root of your project.

@@ -32,5 +32,6 @@ # Usage

```javascript
require("node-oom-heapdump")({
let path = require('path');
require('node-oom-heapdump')({
threshold: 90,
path: "./my_heapdump"
path: path.resolve(__dirname, 'my_heapdump')
});

@@ -52,4 +53,5 @@ ```

* 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 90.
* path - the path where the heapdump ends up when an out of memory error occurs. '.heapsnapshot' is automatically appended. Defaults to this modules' directory.
* addTimestamp - add a timestamp to the out of memory heapdump filename, to make it unique. Default is false.
* limit - optionally, specify a limit to how many heapdumps will be created when being above the threshold. Default is 3.
* path - the path where the heapdump ends up when an out of memory error occurs.
* port - optionally, the alternative DevTools protocol port. Defaults to 9229. Should map on the port given to the --inspect arg.

@@ -56,0 +58,0 @@

@@ -18,3 +18,7 @@ let oomLib = require("../index.js")({

if (i === 3) {
oomLib.deleteHeapSnapshot(path);
oomLib.deleteHeapSnapshot(path).then(() => {
//
}).catch((err) => {
console.error("err", err);
});
setTimeout(function () {

@@ -21,0 +25,0 @@ process.exit(0);

@@ -0,6 +1,9 @@

let path = require('path');
let oom = require("../index.js")({
threshold: 90,
path: "../my_heapdump",
path: path.resolve(__dirname, 'my_heapdump'),
heapdumpOnOOM: true,
limit: 1
limit: 2,
addTimestamp: false
});

@@ -7,0 +10,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc