-
-
Notifications
You must be signed in to change notification settings - Fork 32.6k
async_hooks,worker: fix process.exit() crashes in async fn with async_hook enabled #33347
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
Closed
Closed
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
b523a31
worker: call CancelTerminateExecution() before exiting Locker
addaleax d90c3d1
async_hooks: clear async_id_stack for terminations in more places
addaleax 7b45371
test: regression tests for async_hooks + Promise + Worker interaction
addaleax 3d9d564
fixup! test: regression tests for async_hooks + Promise + Worker inte…
addaleax 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 hidden or 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 hidden or 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
15 changes: 15 additions & 0 deletions
15
test/parallel/test-async-hooks-worker-asyncfn-terminate-1.js
This file contains hidden or 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,15 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
const { Worker } = require('worker_threads'); | ||
|
||
const w = new Worker(` | ||
const { createHook } = require('async_hooks'); | ||
|
||
setImmediate(async () => { | ||
createHook({ init() {} }).enable(); | ||
await 0; | ||
process.exit(); | ||
}); | ||
`, { eval: true }); | ||
|
||
w.on('exit', common.mustCall()); |
21 changes: 21 additions & 0 deletions
21
test/parallel/test-async-hooks-worker-asyncfn-terminate-2.js
This file contains hidden or 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,21 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
const { Worker } = require('worker_threads'); | ||
|
||
// Like test-async-hooks-worker-promise.js but with the `await` and `createHook` | ||
// lines switched, because that resulted in different assertion failures | ||
// (one a Node.js assertion and one a V8 DCHECK) and it seems prudent to | ||
// cover both of those failures. | ||
|
||
const w = new Worker(` | ||
const { createHook } = require('async_hooks'); | ||
|
||
setImmediate(async () => { | ||
await 0; | ||
createHook({ init() {} }).enable(); | ||
process.exit(); | ||
}); | ||
`, { eval: true }); | ||
|
||
w.postMessage({}); | ||
w.on('exit', common.mustCall()); |
20 changes: 20 additions & 0 deletions
20
test/parallel/test-async-hooks-worker-asyncfn-terminate-3.js
This file contains hidden or 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,20 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
const { Worker } = require('worker_threads'); | ||
|
||
// Like test-async-hooks-worker-promise.js but with an additrional statement | ||
// after the `process.exit()` call, that shouldn’t really make a difference | ||
// but apparently does. | ||
|
||
const w = new Worker(` | ||
const { createHook } = require('async_hooks'); | ||
|
||
setImmediate(async () => { | ||
createHook({ init() {} }).enable(); | ||
await 0; | ||
process.exit(); | ||
process._rawDebug('THIS SHOULD NEVER BE REACHED'); | ||
}); | ||
`, { eval: true }); | ||
|
||
w.on('exit', common.mustCall()); |
24 changes: 24 additions & 0 deletions
24
test/parallel/test-async-hooks-worker-asyncfn-terminate-4.js
This file contains hidden or 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,24 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
const assert = require('assert'); | ||
const { Worker } = require('worker_threads'); | ||
|
||
// Like test-async-hooks-worker-promise.js but doing a trivial counter increase | ||
// after process.exit(). This should not make a difference, but apparently it | ||
// does. This is *also* different from test-async-hooks-worker-promise-3.js, | ||
// in that the statement is an ArrayBuffer access rather than a full method, | ||
// which *also* makes a difference even though it shouldn’t. | ||
|
||
const workerData = new Int32Array(new SharedArrayBuffer(4)); | ||
const w = new Worker(` | ||
const { createHook } = require('async_hooks'); | ||
|
||
setImmediate(async () => { | ||
createHook({ init() {} }).enable(); | ||
await 0; | ||
process.exit(); | ||
workerData[0]++; | ||
}); | ||
`, { eval: true, workerData }); | ||
|
||
w.on('exit', common.mustCall(() => assert.strictEqual(workerData[0], 0))); |
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.
Uh oh!
There was an error while loading. Please reload this page.