summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorAnna Henningsen <anna@addaleax.net>2018-10-20 11:51:29 +0200
committerMatheus Marchini <mat@mmarchini.me>2018-10-24 11:20:35 -0300
commit5d80ae3acdd812651b3b193cd31e0b81c214b50e (patch)
treeefb0548ce0f26174dee13feeadab072c2c9461e5 /test
parent036fbdb63d603a64bd8562ec9331dfb7a5c5075c (diff)
downloadandroid-node-v8-5d80ae3acdd812651b3b193cd31e0b81c214b50e.tar.gz
android-node-v8-5d80ae3acdd812651b3b193cd31e0b81c214b50e.tar.bz2
android-node-v8-5d80ae3acdd812651b3b193cd31e0b81c214b50e.zip
trace_events: forbid tracing modifications from worker threads
Forbid modifying tracing state from worker threads, either through the built-in module or inspector sessions, since the main thread owns all global state, and at least the `async_hooks` integration is definitely not thread safe in its current state. PR-URL: https://github.com/nodejs/node/pull/23781 Fixes: https://github.com/nodejs/node/issues/22767 Refs: https://github.com/nodejs/node/issues/22513 Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: Matheus Marchini <mat@mmarchini.me>
Diffstat (limited to 'test')
-rw-r--r--test/parallel/test-trace-events-api-worker-disabled.js11
-rw-r--r--test/parallel/test-trace-events-dynamic-enable-workers-disabled.js28
2 files changed, 39 insertions, 0 deletions
diff --git a/test/parallel/test-trace-events-api-worker-disabled.js b/test/parallel/test-trace-events-api-worker-disabled.js
new file mode 100644
index 0000000000..6140d3a83c
--- /dev/null
+++ b/test/parallel/test-trace-events-api-worker-disabled.js
@@ -0,0 +1,11 @@
+// Flags: --experimental-worker
+'use strict';
+
+const common = require('../common');
+const { Worker } = require('worker_threads');
+
+new Worker("require('trace_events')", { eval: true })
+ .on('error', common.expectsError({
+ code: 'ERR_TRACE_EVENTS_UNAVAILABLE',
+ type: Error
+ }));
diff --git a/test/parallel/test-trace-events-dynamic-enable-workers-disabled.js b/test/parallel/test-trace-events-dynamic-enable-workers-disabled.js
new file mode 100644
index 0000000000..adae50057e
--- /dev/null
+++ b/test/parallel/test-trace-events-dynamic-enable-workers-disabled.js
@@ -0,0 +1,28 @@
+// Flags: --experimental-worker
+'use strict';
+
+const common = require('../common');
+const { Worker } = require('worker_threads');
+
+common.skipIfInspectorDisabled();
+
+if (!process.env.HAS_STARTED_WORKER) {
+ process.env.HAS_STARTED_WORKER = 1;
+ new Worker(__filename);
+ return;
+}
+
+const assert = require('assert');
+const { Session } = require('inspector');
+
+const session = new Session();
+session.connect();
+session.post('NodeTracing.start', {
+ traceConfig: { includedCategories: ['node.perf'] }
+}, common.mustCall((err) => {
+ assert.deepStrictEqual(err, {
+ code: -32000,
+ message:
+ 'Tracing properties can only be changed through main thread sessions'
+ });
+}));