-
Notifications
You must be signed in to change notification settings - Fork 29.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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: #23781 Fixes: #22767 Refs: #22513 Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: Matheus Marchini <mat@mmarchini.me>
- Loading branch information
Showing
7 changed files
with
62 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
})); |
28 changes: 28 additions & 0 deletions
28
test/parallel/test-trace-events-dynamic-enable-workers-disabled.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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' | ||
}); | ||
})); |