Repository navigation
feat(async-worker): fix event-loop hang on env teardown #1759
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
Open
dave-365
wants to merge
10
commits into
nodejs:main
Choose a base branch
from
dave-365:fix/async-worker-hot-reload
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+230
−6
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
9172b2a
feat(async-worker): fix event-loop hang on env teardown
dave-365 a486145
fis:review comments added all test case like termination running and …
dave-365 a046db3
fix(async-worker): remove script evaluation in finalizer and await wo…
86d9a07
fix(async-worker): increase sync timeout to 30s and fix test teardown…
2752b83
refactor(async-worker): rely on teardown flag and remove script evalu…
931edb4
fix(async-progress-worker): replace script probe with clean JS check …
dave-365 cbf2e8f
refactor(async-worker): remove redundant probe and magic number
1a6aadd
fix(async-worker): prevent teardown deadlock and await worker termina…
db8f8b2
rftr: linux unix double check some checksome failed even though windo…
002f2dd
rftr:remove the local variable instead of global
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| 'use strict'; | ||
|
|
||
| const assert = require('assert'); | ||
| const { whichBuildType } = require('./common'); | ||
|
|
||
| // These tests ensure that AsyncProgressWorker can be used in a terminating | ||
| // environment without triggering any crashes, use-after-free, or fatal errors. | ||
|
|
||
| if (process.argv[2] === 'runInChildProcess') { | ||
| const bindingPath = process.argv[3]; | ||
| const testCase = Number(process.argv[4]); | ||
|
|
||
| const binding = require(bindingPath); | ||
|
|
||
| binding.asyncprogressworker.resetPromises(); | ||
|
|
||
| const { Worker } = require('worker_threads'); | ||
|
|
||
| const worker = new Worker( | ||
| __filename, | ||
| { | ||
| argv: [ | ||
| 'runInWorkerThread', | ||
| bindingPath, | ||
| testCase | ||
| ] | ||
| } | ||
| ); | ||
|
|
||
| if (testCase === 0) { | ||
| // Test case 0: Environment teardown occurs while worker is actively running | ||
| binding.asyncprogressworker.waitForWorkerThread(); | ||
| const terminatePromise = worker.terminate(); | ||
| binding.asyncprogressworker.releaseWorkerThread(); | ||
| terminatePromise.then(() => { | ||
| process.exit(0); | ||
| }); | ||
| } else if (testCase === 1) { | ||
| // Test case 1: Worker finishes normally, then environment is torn down | ||
| // (Verifies cleanup hook was safely removed and does not trigger use-after-free on teardown) | ||
| worker.on('exit', () => { | ||
| process.exit(0); | ||
| }); | ||
| } | ||
| } else if (process.argv[2] === 'runInWorkerThread') { | ||
| const bindingPath = process.argv[3]; | ||
| const testCase = Number(process.argv[4]); | ||
|
|
||
| const binding = require(bindingPath); | ||
|
|
||
| if (testCase === 0) { | ||
| binding.asyncprogressworker.doTerminatingWork( | ||
| () => {}, | ||
| () => {} | ||
| ); | ||
| } else if (testCase === 1) { | ||
| binding.asyncprogressworker.doWork( | ||
| 1, | ||
| () => {}, | ||
| () => {} | ||
| ); | ||
| } | ||
| } else { | ||
| module.exports = wrapTest(); | ||
|
|
||
| async function wrapTest () { | ||
| const path = require('path'); | ||
| const buildType = await whichBuildType(); | ||
| test(path.join(__dirname, `build/${buildType}/binding.node`)); | ||
| test(path.join(__dirname, `build/${buildType}/binding_noexcept.node`)); | ||
| } | ||
|
|
||
| function test (bindingPath) { | ||
| const numberOfTestCases = 2; | ||
|
|
||
| for (let i = 0; i < numberOfTestCases; ++i) { | ||
| const childProcess = require('./napi_child').spawnSync( | ||
| process.execPath, | ||
| [ | ||
| __filename, | ||
| 'runInChildProcess', | ||
| bindingPath, | ||
| i | ||
| ] | ||
| ); | ||
|
|
||
| assert.strictEqual( | ||
| childProcess.status, | ||
| 0, | ||
| `Test case ${bindingPath} ${i} failed with status ${childProcess.status}: ${childProcess.stderr}` | ||
| ); | ||
| } | ||
| } | ||
| } |
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
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.