Skip to content

Commit 05f4dff

Browse files
committed
asyncwrap: fix constructor condition for early ret
AsyncWrap should always properly propagate asynchronous calls to any child that is created. Regardless whether kCallInitHook is currently active. The previous logic would always return early if kCallInitHook wasn't set. PR-URL: #732 Reviewed-by: Ben Noordhuis <[email protected]>
1 parent 10277d2 commit 05f4dff

File tree

4 files changed

+18
-1
lines changed

4 files changed

+18
-1
lines changed

src/async-wrap-inl.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ inline AsyncWrap::AsyncWrap(Environment* env,
2121
has_async_queue_(false),
2222
provider_type_(provider) {
2323
// Check user controlled flag to see if the init callback should run.
24-
if (!env->call_async_init_hook())
24+
if (!env->using_asyncwrap())
25+
return;
26+
if (!env->call_async_init_hook() && parent != nullptr)
2527
return;
2628

2729
// TODO(trevnorris): Until it's verified all passed object's are not weak,

src/async-wrap.cc

+2
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ static void SetupHooks(const FunctionCallbackInfo<Value>& args) {
4848
env->set_async_hooks_init_function(args[1].As<Function>());
4949
env->set_async_hooks_pre_function(args[2].As<Function>());
5050
env->set_async_hooks_post_function(args[3].As<Function>());
51+
52+
env->set_using_asyncwrap(true);
5153
}
5254

5355

src/env-inl.h

+9
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ inline Environment::Environment(v8::Local<v8::Context> context,
165165
isolate_data_(IsolateData::GetOrCreate(context->GetIsolate(), loop)),
166166
using_smalloc_alloc_cb_(false),
167167
using_domains_(false),
168+
using_asyncwrap_(false),
168169
printed_error_(false),
169170
debugger_agent_(this),
170171
context_(context->GetIsolate(), context) {
@@ -298,6 +299,14 @@ inline void Environment::set_using_domains(bool value) {
298299
using_domains_ = value;
299300
}
300301

302+
inline bool Environment::using_asyncwrap() const {
303+
return using_asyncwrap_;
304+
}
305+
306+
inline void Environment::set_using_asyncwrap(bool value) {
307+
using_asyncwrap_ = value;
308+
}
309+
301310
inline bool Environment::printed_error() const {
302311
return printed_error_;
303312
}

src/env.h

+4
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,9 @@ class Environment {
395395
inline bool using_domains() const;
396396
inline void set_using_domains(bool value);
397397

398+
inline bool using_asyncwrap() const;
399+
inline void set_using_asyncwrap(bool value);
400+
398401
inline bool printed_error() const;
399402
inline void set_printed_error(bool value);
400403

@@ -479,6 +482,7 @@ class Environment {
479482
ares_task_list cares_task_list_;
480483
bool using_smalloc_alloc_cb_;
481484
bool using_domains_;
485+
bool using_asyncwrap_;
482486
bool printed_error_;
483487
debugger::Agent debugger_agent_;
484488

0 commit comments

Comments
 (0)