diff options
author | Andreas Madsen <amwebdk@gmail.com> | 2017-10-19 12:43:40 +0200 |
---|---|---|
committer | Andreas Madsen <amwebdk@gmail.com> | 2017-10-19 12:45:21 +0200 |
commit | 7c079d12612ddebc68a24eb3c55efecd8b8a6186 (patch) | |
tree | 99780ecfb4bbdad3a6ecc7685384eb3debca79d3 /src | |
parent | f8ef2e2bf95dd65cb06a7f5e581e856c302f0793 (diff) | |
download | android-node-v8-7c079d12612ddebc68a24eb3c55efecd8b8a6186.tar.gz android-node-v8-7c079d12612ddebc68a24eb3c55efecd8b8a6186.tar.bz2 android-node-v8-7c079d12612ddebc68a24eb3c55efecd8b8a6186.zip |
async_hooks: skip runtime checks when disabled
PR-URL: https://github.com/nodejs/node/pull/15454
Ref: https://github.com/nodejs/node/pull/14387
Ref: https://github.com/nodejs/node/pull/14722
Ref: https://github.com/nodejs/node/issues/14717
Ref: https://github.com/nodejs/node/issues/15448
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Diffstat (limited to 'src')
-rw-r--r-- | src/async-wrap.cc | 1 | ||||
-rw-r--r-- | src/env-inl.h | 23 | ||||
-rw-r--r-- | src/env.h | 3 | ||||
-rw-r--r-- | src/node.cc | 22 |
4 files changed, 40 insertions, 9 deletions
diff --git a/src/async-wrap.cc b/src/async-wrap.cc index a16d938889..36480b3232 100644 --- a/src/async-wrap.cc +++ b/src/async-wrap.cc @@ -526,6 +526,7 @@ void AsyncWrap::Initialize(Local<Object> target, SET_HOOKS_CONSTANT(kDestroy); SET_HOOKS_CONSTANT(kPromiseResolve); SET_HOOKS_CONSTANT(kTotals); + SET_HOOKS_CONSTANT(kCheck); SET_HOOKS_CONSTANT(kExecutionAsyncId); SET_HOOKS_CONSTANT(kTriggerAsyncId); SET_HOOKS_CONSTANT(kAsyncIdCounter); diff --git a/src/env-inl.h b/src/env-inl.h index c8f8b21e03..62dc6e1191 100644 --- a/src/env-inl.h +++ b/src/env-inl.h @@ -129,10 +129,19 @@ inline v8::Local<v8::String> Environment::AsyncHooks::provider_string(int idx) { return providers_[idx].Get(isolate_); } +inline void Environment::AsyncHooks::force_checks() { + // fields_ does not have the += operator defined + fields_[kCheck] = fields_[kCheck] + 1; +} + inline void Environment::AsyncHooks::push_async_ids(double async_id, double trigger_async_id) { - CHECK_GE(async_id, -1); - CHECK_GE(trigger_async_id, -1); + // Since async_hooks is experimental, do only perform the check + // when async_hooks is enabled. + if (fields_[kCheck] > 0) { + CHECK_GE(async_id, -1); + CHECK_GE(trigger_async_id, -1); + } async_ids_stack_.push({ async_id_fields_[kExecutionAsyncId], async_id_fields_[kTriggerAsyncId] }); @@ -145,9 +154,11 @@ inline bool Environment::AsyncHooks::pop_async_id(double async_id) { // stack was multiple MakeCallback()'s deep. if (async_ids_stack_.empty()) return false; - // Ask for the async_id to be restored as a sanity check that the stack + // Ask for the async_id to be restored as a check that the stack // hasn't been corrupted. - if (async_id_fields_[kExecutionAsyncId] != async_id) { + // Since async_hooks is experimental, do only perform the check + // when async_hooks is enabled. + if (fields_[kCheck] > 0 && async_id_fields_[kExecutionAsyncId] != async_id) { fprintf(stderr, "Error: async hook stack has become corrupted (" "actual: %.f, expected: %.f)\n", @@ -185,7 +196,9 @@ inline Environment::AsyncHooks::InitScope::InitScope( Environment* env, double init_trigger_async_id) : env_(env), async_id_fields_ref_(env->async_hooks()->async_id_fields()) { - CHECK_GE(init_trigger_async_id, -1); + if (env_->async_hooks()->fields()[AsyncHooks::kCheck] > 0) { + CHECK_GE(init_trigger_async_id, -1); + } env->async_hooks()->push_async_ids( async_id_fields_ref_[AsyncHooks::kExecutionAsyncId], init_trigger_async_id); @@ -387,6 +387,7 @@ class Environment { kDestroy, kPromiseResolve, kTotals, + kCheck, kFieldsCount, }; @@ -408,6 +409,8 @@ class Environment { inline v8::Local<v8::String> provider_string(int idx); + inline void force_checks(); + inline void push_async_ids(double async_id, double trigger_async_id); inline bool pop_async_id(double async_id); inline size_t stack_size(); diff --git a/src/node.cc b/src/node.cc index 1bc75abef3..88e353656b 100644 --- a/src/node.cc +++ b/src/node.cc @@ -173,6 +173,7 @@ static bool syntax_check_only = false; static bool trace_deprecation = false; static bool throw_deprecation = false; static bool trace_sync_io = false; +static bool force_async_hooks_checks = false; static bool track_heap_objects = false; static const char* eval_string = nullptr; static std::vector<std::string> preload_modules; @@ -1440,8 +1441,10 @@ void InternalCallbackScope::Close() { // Make sure the stack unwound properly. If there are nested MakeCallback's // then it should return early and not reach this code. - CHECK_EQ(env_->execution_async_id(), 0); - CHECK_EQ(env_->trigger_async_id(), 0); + if (env_->async_hooks()->fields()[AsyncHooks::kTotals]) { + CHECK_EQ(env_->execution_async_id(), 0); + CHECK_EQ(env_->trigger_async_id(), 0); + } Local<Object> process = env_->process_object(); @@ -1450,8 +1453,10 @@ void InternalCallbackScope::Close() { return; } - CHECK_EQ(env_->execution_async_id(), 0); - CHECK_EQ(env_->trigger_async_id(), 0); + if (env_->async_hooks()->fields()[AsyncHooks::kTotals]) { + CHECK_EQ(env_->execution_async_id(), 0); + CHECK_EQ(env_->trigger_async_id(), 0); + } if (env_->tick_callback_function()->Call(process, 0, nullptr).IsEmpty()) { failed_ = true; @@ -3894,6 +3899,8 @@ static void PrintHelp() { " stderr\n" " --trace-sync-io show stack trace when use of sync IO\n" " is detected after the first tick\n" + " --force-async-hooks-checks\n" + " enables checks for async_hooks\n" " --trace-events-enabled track trace events\n" " --trace-event-categories comma separated list of trace event\n" " categories to record\n" @@ -4019,6 +4026,7 @@ static void CheckIfAllowedInEnv(const char* exe, bool is_env, "--trace-warnings", "--redirect-warnings", "--trace-sync-io", + "--force-async-hooks-checks", "--trace-events-enabled", "--trace-events-categories", "--track-heap-objects", @@ -4157,6 +4165,8 @@ static void ParseArgs(int* argc, trace_deprecation = true; } else if (strcmp(arg, "--trace-sync-io") == 0) { trace_sync_io = true; + } else if (strcmp(arg, "--force-async-hooks-checks") == 0) { + force_async_hooks_checks = true; } else if (strcmp(arg, "--trace-events-enabled") == 0) { trace_enabled = true; } else if (strcmp(arg, "--trace-event-categories") == 0) { @@ -4805,6 +4815,10 @@ inline int Start(Isolate* isolate, IsolateData* isolate_data, env.set_abort_on_uncaught_exception(abort_on_uncaught_exception); + if (force_async_hooks_checks) { + env.async_hooks()->force_checks(); + } + { Environment::AsyncCallbackScope callback_scope(&env); env.async_hooks()->push_async_ids(1, 0); |