-
-
Notifications
You must be signed in to change notification settings - Fork 35.4k
src: fix Worker termination in inspector.waitForDebugger
#52527
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
de5f1b7
6a0142e
5035b9c
9c210e9
fcbd1b3
e500544
35002b6
ee7472d
d7a556c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| // Flags: --inspect=0 | ||
| import * as common from '../common/index.mjs'; | ||
| common.skipIfInspectorDisabled(); | ||
|
|
||
| import { isMainThread, Worker } from 'node:worker_threads'; | ||
| import { fileURLToPath } from 'node:url'; | ||
| import inspector from 'node:inspector'; | ||
|
|
||
| // Ref: https://github.com/nodejs/node/issues/52467 | ||
| // - worker.terminate() should terminate the worker and the pending | ||
| // inspector.waitForDebugger(). | ||
| if (isMainThread) { | ||
| const worker = new Worker(fileURLToPath(import.meta.url)); | ||
| await new Promise((r) => setTimeout(r, 2_000)); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using timeout to wait until a worker is ready can be flaky on slow CI machines. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This could be more stable approach: // Flags: --inspect=0
import * as common from '../common/index.mjs';
common.skipIfInspectorDisabled();
-import { isMainThread, Worker } from 'node:worker_threads';
+import { isMainThread, parentPort, Worker } from 'node:worker_threads';
import { fileURLToPath } from 'node:url';
import inspector from 'node:inspector';
// Ref: https://github.com/nodejs/node/issues/52467
// - worker.terminate() should terminate the worker and the pending
// inspector.waitForDebugger().
if (isMainThread) {
const worker = new Worker(fileURLToPath(import.meta.url));
- await new Promise((r) => setTimeout(r, 2_000));
+ await new Promise((r) => worker.on("message", r));
worker.on('exit', common.mustCall());
await worker.terminate();
} else {
inspector.open();
+ parentPort.postMessage("inspector is open")
inspector.waitForDebugger();
}
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated using
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using MessagePort doesn't seem to be enough. I tried using |
||
|
|
||
| worker.on('exit', common.mustCall()); | ||
| await worker.terminate(); | ||
| } else { | ||
| inspector.open(); | ||
| inspector.waitForDebugger(); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| // Flags: --inspect=0 | ||
| import * as common from '../common/index.mjs'; | ||
| common.skipIfInspectorDisabled(); | ||
|
|
||
| import { isMainThread, Worker } from 'node:worker_threads'; | ||
| import { fileURLToPath } from 'node:url'; | ||
| import inspector from 'node:inspector'; | ||
| import assert from 'node:assert'; | ||
|
|
||
| // Ref: https://github.com/nodejs/node/issues/52467 | ||
| // - process.exit() should kill the main thread's process. | ||
| if (isMainThread) { | ||
| new Worker(fileURLToPath(import.meta.url)); | ||
| await new Promise((r) => setTimeout(r, 2_000)); | ||
|
|
||
| process.on('exit', (status) => assert.strictEqual(status, 0)); | ||
| process.exit(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I believe the broader question is if In the first case (autoattach) worker should only wait if there are connected sessions that asked to be attached to workers. I apologize if I am not making sense, haven't worked on this in years...
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (Feel free to dismiss my comments as I am not sure I am up to date with the current state of inspector) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
As far as I know,
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Applied.
If the main thread runs to completion (assuming it runs without Users seem to be using
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ack. Thank you for the explanations. |
||
| } else { | ||
| inspector.open(); | ||
| inspector.waitForDebugger(); | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.