-
Notifications
You must be signed in to change notification settings - Fork 28.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
src: avoid draining platform tasks at FreeEnvironment
At the point of `FreeEnvironment` and onwards, no JavaScript execution associated with the Environment should be triggered. Avoid draining platform tasks that can trigger JavaScript execution in `FreeEnvironment`. The holder of `node::Environment` should immediately call `node::MultiIsolatePlatform::UnregisterIsolate` and `v8::Isolate::Dispose` to cancel pending foreground tasks and join concurrent tasks after the environment was freed. `NodePlatform` can properly handle the case in `RunForegroundTask` when an Isolate out-lives its associated `node::Environment`. PR-URL: #51290 Fixes: #47748 Fixes: #49344 Reviewed-By: Vinícius Lourenço Claro Cardoso <contact@viniciusl.com.br> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
- Loading branch information
1 parent
e5fc8ec
commit d9d9e62
Showing
4 changed files
with
46 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// Flags: --expose-gc | ||
'use strict'; | ||
const common = require('../common'); | ||
|
||
// This test verifies that when a V8 FinalizationRegistryCleanupTask is queue | ||
// at the last moment when JavaScript can be executed, the callback of a | ||
// FinalizationRegistry will not be invoked and the process should exit | ||
// normally. | ||
|
||
const reg = new FinalizationRegistry( | ||
common.mustNotCall('This FinalizationRegistry callback should never be called')); | ||
|
||
function register() { | ||
// Create a temporary object in a new function scope to allow it to be GC-ed. | ||
reg.register({}); | ||
} | ||
|
||
process.on('exit', () => { | ||
// This is the final chance to execute JavaScript. | ||
register(); | ||
// Queue a FinalizationRegistryCleanupTask by a testing gc request. | ||
global.gc(); | ||
}); |