Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
c60cd67
test: skip test for dynamically linked OpenSSL
richardlau Apr 15, 2024
678641f
deps: V8: cherry-pick d15d49b09dc7
Bo98 Apr 2, 2024
6689a98
http: remove closeIdleConnections function while calling server close
kumarrishav Apr 2, 2024
5186e45
test: deflake test-http-regr-gh-2928
lpinca Sep 9, 2023
5cec2ef
test: reduce the number of requests and parsers
lpinca Oct 20, 2023
5e93eae
doc: add release key for marco-ippolito
marco-ippolito Mar 28, 2024
e28316d
deps: update nghttp2 to 1.58.0
nodejs-github-bot Nov 2, 2023
3c9dbbf
deps: update nghttp2 to 1.59.0
nodejs-github-bot Feb 1, 2024
1b6fa70
deps: update nghttp2 to 1.60.0
nodejs-github-bot Mar 5, 2024
a9f3b9d
deps: update nghttp2 to 1.61.0
nodejs-github-bot Apr 16, 2024
b56f66e
deps: update simdutf to 4.0.9
nodejs-github-bot Mar 9, 2024
be30309
deps: update simdutf to 5.0.0
lemire Mar 20, 2024
5114cbe
deps: update simdutf to 5.2.3
anonrig Apr 4, 2024
209823d
deps: update simdutf to 5.2.4
nodejs-github-bot Apr 13, 2024
052b0ba
deps: upgrade npm to 10.5.1
npm-cli-bot Apr 7, 2024
b199889
deps: update corepack to 0.26.0
nodejs-github-bot Mar 12, 2024
7a8c7b6
deps: update ada to 2.7.7
nodejs-github-bot Mar 12, 2024
9500817
deps: update acorn to 8.11.2
nodejs-github-bot Oct 31, 2023
c86550e
deps: update acorn-walk to 8.3.0
nodejs-github-bot Oct 29, 2023
dddb7eb
deps: update acorn-walk to 8.3.1
nodejs-github-bot Dec 10, 2023
12f28f3
deps: update acorn to 8.11.3
nodejs-github-bot Jan 2, 2024
2c53ff3
deps: update acorn-walk to 8.3.2
nodejs-github-bot Jan 22, 2024
71616e8
node-api: make tsfn accept napi_finalize once more
gabrielschulhof Mar 9, 2024
8fd5a35
deps: upgrade npm to 10.5.2
npm-cli-bot Apr 12, 2024
28c0c78
deps: update ngtcp2 and nghttp3
jasnell Dec 26, 2023
1aa9da4
deps: add nghttp3/**/.deps to .gitignore
lpinca Jan 8, 2024
3034968
deps: update ngtcp2 to 1.1.0
nodejs-github-bot Jan 22, 2024
1f489a3
deps: update ngtcp2 to 1.2.0
nodejs-github-bot Jan 31, 2024
78f84eb
deps: update ngtcp2 to 1.3.0
nodejs-github-bot Feb 26, 2024
7f5dd44
deps: upgrade npm to 10.7.0
npm-cli-bot May 1, 2024
14e857b
deps: update corepack to 0.28.0
nodejs-github-bot Apr 23, 2024
e4ea2db
deps: update c-ares to 1.28.1
nodejs-github-bot Apr 4, 2024
af3e320
deps: update ada to 2.7.8
nodejs-github-bot Apr 14, 2024
755399d
deps: update zlib to 1.3.0.1-motley-24342f6
nodejs-github-bot Mar 19, 2024
1152d7f
deps: update zlib to 1.3.0.1-motley-24c07df
nodejs-github-bot Mar 27, 2024
0c260e1
deps: update zlib to 1.3.0.1-motley-7d77fb7
nodejs-github-bot Apr 17, 2024
1147fee
doc: remove ableist language from crypto
10xLaCroixDrinker Mar 17, 2024
351ef18
test: v8: Add test-linux-perf-logger test suite
lukealbao Oct 25, 2023
e5fc8ec
test: skip v8-updates/test-linux-perf
targos Oct 7, 2023
d9d9e62
src: avoid draining platform tasks at FreeEnvironment
legendecas Jan 8, 2024
64903b1
2024-05-21, Version 18.20.3 'Hydrogen' (LTS)
richardlau May 16, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
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
legendecas authored and richardlau committed May 16, 2024
commit d9d9e62474b41f5a937d1900d68ac4739810bee9
7 changes: 0 additions & 7 deletions src/api/environment.cc
Original file line number Diff line number Diff line change
Expand Up @@ -451,13 +451,6 @@ void FreeEnvironment(Environment* env) {
RunAtExit(env);
}

// This call needs to be made while the `Environment` is still alive
// because we assume that it is available for async tracking in the
// NodePlatform implementation.
MultiIsolatePlatform* platform = env->isolate_data()->platform();
if (platform != nullptr)
platform->DrainTasks(isolate);

delete env;
}

Expand Down
20 changes: 18 additions & 2 deletions src/node_main_instance.cc
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,24 @@ NodeMainInstance::~NodeMainInstance() {
if (isolate_params_ == nullptr) {
return;
}
// This should only be done on a main instance that owns its isolate.
platform_->UnregisterIsolate(isolate_);

{
#ifdef DEBUG
// node::Environment has been disposed and no JavaScript Execution is
// allowed at this point.
// Create a scope to check that no JavaScript is executed in debug build
// and proactively crash the process in the case JavaScript is being
// executed.
// Isolate::Dispose() must be invoked outside of this scope to avoid
// use-after-free.
Isolate::DisallowJavascriptExecutionScope disallow_js(
isolate_, Isolate::DisallowJavascriptExecutionScope::CRASH_ON_FAILURE);
#endif
// This should only be done on a main instance that owns its isolate.
// IsolateData must be freed before UnregisterIsolate() is called.
isolate_data_.reset();
platform_->UnregisterIsolate(isolate_);
}
isolate_->Dispose();
}

Expand Down
5 changes: 5 additions & 0 deletions src/node_platform.cc
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,11 @@ void PerIsolatePlatformData::RunForegroundTask(std::unique_ptr<Task> task) {
InternalCallbackScope::kNoFlags);
task->Run();
} else {
// When the Environment was freed, the tasks of the Isolate should also be
// canceled by `NodePlatform::UnregisterIsolate`. However, if the embedder
// request to run the foreground task after the Environment was freed, run
// the task without InternalCallbackScope.

// The task is moved out of InternalCallbackScope if env is not available.
// This is a required else block, and should not be removed.
// See comment: https://github.com/nodejs/node/pull/34688#pullrequestreview-463867489
Expand Down
23 changes: 23 additions & 0 deletions test/parallel/test-finalization-registry-shutdown.js
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();
});