GeezerVison is showing github.com — async_hooks: clear async_id_stack for terminations in more places · nodejs/node@dd4789b
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: src/api/callback.cc +10-3Lines changed: 10 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -84,9 +84,13 @@ void InternalCallbackScope::Close() { |
84 | 84 | closed_ = true; |
85 | 85 |
|
86 | 86 | if (!env_->can_call_into_js()) return; |
87 | | - if (failed_ && !env_->is_main_thread() && env_->is_stopping()) { |
88 | | - env_->async_hooks()->clear_async_id_stack(); |
89 | | - } |
| 87 | + auto perform_stopping_check = [&]() { |
| 88 | + if (env_->is_stopping()) { |
| 89 | + MarkAsFailed(); |
| 90 | + env_->async_hooks()->clear_async_id_stack(); |
| 91 | + } |
| 92 | + }; |
| 93 | + perform_stopping_check(); |
90 | 94 |
|
91 | 95 | if (!failed_ && async_context_.async_id != 0 && !skip_hooks_) { |
92 | 96 | AsyncWrap::EmitAfter(env_, async_context_.async_id); |
@@ -109,6 +113,8 @@ void InternalCallbackScope::Close() { |
109 | 113 |
|
110 | 114 | if (!tick_info->has_tick_scheduled()) { |
111 | 115 | MicrotasksScope::PerformCheckpoint(env_->isolate()); |
| 116 | + |
| 117 | + perform_stopping_check(); |
112 | 118 | } |
113 | 119 |
|
114 | 120 | // Make sure the stack unwound properly. If there are nested MakeCallback's |
@@ -136,6 +142,7 @@ void InternalCallbackScope::Close() { |
136 | 142 | if (tick_callback->Call(env_->context(), process, 0, nullptr).IsEmpty()) { |
137 | 143 | failed_ = true; |
138 | 144 | } |
| 145 | + perform_stopping_check(); |
139 | 146 | } |
140 | 147 |
|
141 | 148 | MaybeLocal<Value> InternalMakeCallback(Environment* env, |
|