Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorChengzhong Wu <chengzhong.wcz@alibaba-inc.com>2022-05-17 06:40:40 +0300
committerBryan English <bryan@bryanenglish.com>2022-05-30 19:33:53 +0300
commitd91b489784df7fe591525d04cafb8ad175fc8d2a (patch)
treec18af1396c685ab16d9bd30cff03bbf8b3a2469b /test
parent11c783fa63733a8cff9d983b233c04fac88359b3 (diff)
worker: fix heap snapshot crash on exit
Worker.parent_port_ can be released before the exit event of Worker. The parent_port_ is not owned by `node::worker::Worker`, thus the reference to it is not always valid, and accessing it at exit crashes the process. As the Worker.parent_port_ is only used in the memory info tracking, it can be safely removed. PR-URL: https://github.com/nodejs/node/pull/43123 Fixes: https://github.com/nodejs/node/issues/43122 Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
Diffstat (limited to 'test')
-rw-r--r--test/parallel/test-worker-exit-heapsnapshot.js17
-rw-r--r--test/pummel/test-heapdump-worker.js8
2 files changed, 17 insertions, 8 deletions
diff --git a/test/parallel/test-worker-exit-heapsnapshot.js b/test/parallel/test-worker-exit-heapsnapshot.js
new file mode 100644
index 00000000000..a7b7b26ecae
--- /dev/null
+++ b/test/parallel/test-worker-exit-heapsnapshot.js
@@ -0,0 +1,17 @@
+'use strict';
+const common = require('../common');
+const assert = require('assert');
+const { getHeapSnapshot } = require('v8');
+const { isMainThread, Worker } = require('worker_threads');
+
+// Checks taking heap snapshot at the exit event listener of Worker doesn't
+// crash the process.
+// Regression for https://github.com/nodejs/node/issues/43122.
+if (isMainThread) {
+ const worker = new Worker(__filename);
+
+ worker.once('exit', common.mustCall((code) => {
+ assert.strictEqual(code, 0);
+ getHeapSnapshot().pipe(process.stdout);
+ }));
+}
diff --git a/test/pummel/test-heapdump-worker.js b/test/pummel/test-heapdump-worker.js
index 0e8322affb5..d494de50922 100644
--- a/test/pummel/test-heapdump-worker.js
+++ b/test/pummel/test-heapdump-worker.js
@@ -6,14 +6,6 @@ const { Worker } = require('worker_threads');
validateSnapshotNodes('Node / Worker', []);
const worker = new Worker('setInterval(() => {}, 100);', { eval: true });
-validateSnapshotNodes('Node / Worker', [
- {
- children: [
- { node_name: 'Node / MessagePort', edge_name: 'parent_port' },
- { node_name: 'Worker', edge_name: 'wrapped' },
- ]
- },
-]);
validateSnapshotNodes('Node / MessagePort', [
{
children: [