summaryrefslogtreecommitdiff
path: root/src/api
diff options
context:
space:
mode:
authorAnna Henningsen <anna@addaleax.net>2020-05-11 02:30:02 +0200
committerAnna Henningsen <anna@addaleax.net>2020-05-15 19:38:25 +0200
commitfe4e4ddc718a359b97f3fc89e5ff44625dcd6e7d (patch)
treedba5eb4bed29313e74f8c8186066385a0100ca57 /src/api
parentdd0980ecc287537a48cd5d6f7f803cd8c681dbdb (diff)
downloadnode-new-fe4e4ddc718a359b97f3fc89e5ff44625dcd6e7d.tar.gz
async_hooks: clear async_id_stack for terminations in more places
Termination exceptions are similar to uncaught exceptions in that they should clear the async id stack, because no ongoing async callbacks will be brought to completion when execution terminates. Previously, there was a check that made sure that that happened when the termination occurred during the callback itself, but no such check was in place for the case that the termination occurred during microtasks started by them. This commit adds such a check, both for microtasks and the `nextTick` queue. The latter addition doesn’t fix a crash, but still makes sense conceptually. The condition here is also flipped from applying only on Worker threads to also applying on the main thread, and setting the `failed_` flag rather than reading it. The former makes sense because the public C++ `Stop(env)` API can have the same effect as worker thread termination, but on the main thread rather than a Worker thread. PR-URL: https://github.com/nodejs/node/pull/33347 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: David Carlier <devnexen@gmail.com>
Diffstat (limited to 'src/api')
-rw-r--r--src/api/callback.cc13
1 files changed, 10 insertions, 3 deletions
diff --git a/src/api/callback.cc b/src/api/callback.cc
index f7e7ddedfa..c8934e1cd3 100644
--- a/src/api/callback.cc
+++ b/src/api/callback.cc
@@ -84,9 +84,13 @@ void InternalCallbackScope::Close() {
closed_ = true;
if (!env_->can_call_into_js()) return;
- if (failed_ && !env_->is_main_thread() && env_->is_stopping()) {
- env_->async_hooks()->clear_async_id_stack();
- }
+ auto perform_stopping_check = [&]() {
+ if (env_->is_stopping()) {
+ MarkAsFailed();
+ env_->async_hooks()->clear_async_id_stack();
+ }
+ };
+ perform_stopping_check();
if (!failed_ && async_context_.async_id != 0 && !skip_hooks_) {
AsyncWrap::EmitAfter(env_, async_context_.async_id);
@@ -109,6 +113,8 @@ void InternalCallbackScope::Close() {
if (!tick_info->has_tick_scheduled()) {
MicrotasksScope::PerformCheckpoint(env_->isolate());
+
+ perform_stopping_check();
}
// Make sure the stack unwound properly. If there are nested MakeCallback's
@@ -136,6 +142,7 @@ void InternalCallbackScope::Close() {
if (tick_callback->Call(env_->context(), process, 0, nullptr).IsEmpty()) {
failed_ = true;
}
+ perform_stopping_check();
}
MaybeLocal<Value> InternalMakeCallback(Environment* env,