@sentio/runtime 2.58.0-rc.7 → 2.58.0-rc.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/processor-runner.js +31 -9
- package/lib/processor-runner.js.map +1 -1
- package/package.json +1 -1
- package/src/processor-runner.ts +37 -11
package/lib/processor-runner.js
CHANGED
@@ -26493,15 +26493,7 @@ var httpServer = http2.createServer(async function(req, res) {
|
|
26493
26493
|
case "/heap": {
|
26494
26494
|
try {
|
26495
26495
|
const file = "/tmp/" + Date.now() + ".heapsnapshot";
|
26496
|
-
|
26497
|
-
const fd = import_fs_extra2.default.openSync(file, "w");
|
26498
|
-
session.connect();
|
26499
|
-
session.on("HeapProfiler.addHeapSnapshotChunk", (m) => {
|
26500
|
-
import_fs_extra2.default.writeSync(fd, m.params.chunk);
|
26501
|
-
});
|
26502
|
-
await session.post("HeapProfiler.takeHeapSnapshot");
|
26503
|
-
session.disconnect();
|
26504
|
-
import_fs_extra2.default.closeSync(fd);
|
26496
|
+
await dumpHeap(file);
|
26505
26497
|
const readStream = import_fs_extra2.default.createReadStream(file);
|
26506
26498
|
res.writeHead(200, { "Content-Type": "application/json" });
|
26507
26499
|
readStream.pipe(res);
|
@@ -26554,6 +26546,36 @@ process.on("SIGINT", function() {
|
|
26554
26546
|
baseService.unhandled = reason;
|
26555
26547
|
}
|
26556
26548
|
});
|
26549
|
+
if (process.env["OOM_DUMP_MEMORY_SIZE_GB"]) {
|
26550
|
+
let dumping = false;
|
26551
|
+
const memorySize = parseInt(process.env["OOM_DUMP_MEMORY_SIZE_GB"], 10);
|
26552
|
+
console.log("heap dumping is enabled, limit set to ", memorySize, "gb");
|
26553
|
+
setInterval(async () => {
|
26554
|
+
const mem = process.memoryUsage();
|
26555
|
+
if (mem.heapTotal > memorySize * 1024 * 1024 * 1024 && !dumping) {
|
26556
|
+
const file = "/tmp/" + Date.now() + ".heapsnapshot";
|
26557
|
+
dumping = true;
|
26558
|
+
await dumpHeap(file);
|
26559
|
+
process.exit(11);
|
26560
|
+
}
|
26561
|
+
}, 1e3 * 60);
|
26562
|
+
}
|
26563
|
+
async function dumpHeap(file) {
|
26564
|
+
console.log("Heap dumping to", file);
|
26565
|
+
const session = new Session();
|
26566
|
+
const fd = import_fs_extra2.default.openSync(file, "w");
|
26567
|
+
try {
|
26568
|
+
session.connect();
|
26569
|
+
session.on("HeapProfiler.addHeapSnapshotChunk", (m) => {
|
26570
|
+
import_fs_extra2.default.writeSync(fd, m.params.chunk);
|
26571
|
+
});
|
26572
|
+
await session.post("HeapProfiler.takeHeapSnapshot");
|
26573
|
+
console.log("Heap dumped to", file);
|
26574
|
+
} finally {
|
26575
|
+
session.disconnect();
|
26576
|
+
import_fs_extra2.default.closeSync(fd);
|
26577
|
+
}
|
26578
|
+
}
|
26557
26579
|
function shutdownServers(exitCode) {
|
26558
26580
|
server?.forceShutdown();
|
26559
26581
|
console.log("RPC server shut down");
|