-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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
process,worker: ensure code after exit() effectless #45620
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
de62467
process,worker: ensure code after exit() effectless
ywave620 37cccd0
process,worker: ensure code after exit() effectless
ywave620 0f66f9e
process,worker: ensure code after exit() effectless
ywave620 ad562e1
process,worker: ensure code after exit() effectless
ywave620 0c91220
process,worker: ensure code after exit() effectless
ywave620 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 |
---|---|---|
|
@@ -12,6 +12,7 @@ const { Worker } = require('worker_threads'); | |
const workerData = new Int32Array(new SharedArrayBuffer(4)); | ||
const w = new Worker(` | ||
const { createHook } = require('async_hooks'); | ||
const { workerData } = require('worker_threads'); | ||
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 original author forgot to add this import. And this is why the |
||
|
||
setImmediate(async () => { | ||
createHook({ init() {} }).enable(); | ||
|
18 changes: 18 additions & 0 deletions
18
test/parallel/test-worker-voluntarily-exit-followed-by-addition.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,18 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
const assert = require('assert'); | ||
const { Worker, isMainThread } = require('worker_threads'); | ||
|
||
if (isMainThread) { | ||
const workerData = new Int32Array(new SharedArrayBuffer(4)); | ||
new Worker(__filename, { | ||
workerData, | ||
}); | ||
process.on('beforeExit', common.mustCall(() => { | ||
assert.strictEqual(workerData[0], 0); | ||
})); | ||
} else { | ||
const { workerData } = require('worker_threads'); | ||
process.exit(); | ||
workerData[0] = 1; | ||
} |
23 changes: 23 additions & 0 deletions
23
test/parallel/test-worker-voluntarily-exit-followed-by-throw.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,23 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
const assert = require('assert'); | ||
const { Worker, isMainThread } = require('worker_threads'); | ||
|
||
if (isMainThread) { | ||
const workerData = new Int32Array(new SharedArrayBuffer(4)); | ||
new Worker(__filename, { | ||
workerData, | ||
}); | ||
process.on('beforeExit', common.mustCall(() => { | ||
assert.strictEqual(workerData[0], 0); | ||
})); | ||
} else { | ||
const { workerData } = require('worker_threads'); | ||
try { | ||
process.exit(); | ||
throw new Error('xxx'); | ||
// eslint-disable-next-line no-unused-vars | ||
} catch (err) { | ||
ywave620 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
workerData[0] = 1; | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that if
this->isolate->IsExecutionTerminating()
is true, we can not callcan_call_into_js()
, because that will extract thenode::Environment
by calling v8 API onthis->isolate
, which will again hit the assertion: