Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnna Henningsen <anna@addaleax.net>2019-11-26 19:09:27 +0300
committerAnna Henningsen <anna@addaleax.net>2019-11-30 05:57:24 +0300
commit6c249c0982b0a5bb1ee3a9cc86c88dde55dfc887 (patch)
treed1cbb13990292b560d2b00eec6d24ee9ee2bfa5c /src/env.cc
parentbea25016d12ee9a672b02d5f10b1f0a28dbe400d (diff)
src: run native immediates during Environment cleanup
This can be necessary, because some parts of the Node.js code base perform cleanup operations in the Immediate callbacks, e.g. HTTP/2. This resolves flakiness in an HTTP/2 test that failed when a `SetImmediate()` callback was not run or destroyed before the `Environment` destructor started, because that callback held a strong reference to the `Http2Session` object and the expectation was that no such objects exist once the `Environment` constructor starts. Another, slightly more direct, alternative would have been to clear the immediate queue rather than to run it. However, this approach seems to make more sense as code generally assumes that the `SetImmediate()` callback will always run; For example, N-API uses an immediate callback to call buffer finalization callbacks. Unref’ed immediates are skipped, as the expectation is generally that they may not run anyway. Fixes: https://github.com/nodejs/node/issues/30643 PR-URL: https://github.com/nodejs/node/pull/30666 Refs: https://github.com/nodejs/node/pull/30374 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'src/env.cc')
-rw-r--r--src/env.cc8
1 files changed, 6 insertions, 2 deletions
diff --git a/src/env.cc b/src/env.cc
index 36a1c1119dc..dfd1e6385f8 100644
--- a/src/env.cc
+++ b/src/env.cc
@@ -543,6 +543,8 @@ void Environment::CleanupHandles() {
Isolate::DisallowJavascriptExecutionScope disallow_js(isolate(),
Isolate::DisallowJavascriptExecutionScope::THROW_ON_FAILURE);
+ RunAndClearNativeImmediates(true /* skip SetUnrefImmediate()s */);
+
for (ReqWrapBase* request : req_wrap_queue_)
request->Cancel();
@@ -658,7 +660,7 @@ void Environment::AtExit(void (*cb)(void* arg), void* arg) {
at_exit_functions_.push_front(ExitCallback{cb, arg});
}
-void Environment::RunAndClearNativeImmediates() {
+void Environment::RunAndClearNativeImmediates(bool only_refed) {
TraceEventScope trace_scope(TRACING_CATEGORY_NODE1(environment),
"RunAndClearNativeImmediates", this);
size_t ref_count = 0;
@@ -675,7 +677,9 @@ void Environment::RunAndClearNativeImmediates() {
if (head->is_refed())
ref_count++;
- head->Call(this);
+ if (head->is_refed() || !only_refed)
+ head->Call(this);
+
if (UNLIKELY(try_catch.HasCaught())) {
if (!try_catch.HasTerminated() && can_call_into_js())
errors::TriggerUncaughtException(isolate(), try_catch);