Skip to content
This repository was archived by the owner on Aug 31, 2018. It is now read-only.

Commit 13be443

Browse files
AndreasMadsenQard
authored andcommitted
async_hooks: enable runtime checks by default
Ref: nodejs/node#15454 PR-URL: nodejs/node#16318 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Refael Ackermann <refack@gmail.com>
1 parent 3257f85 commit 13be443

File tree

8 files changed

+26
-63
lines changed

8 files changed

+26
-63
lines changed

doc/api/cli.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -208,13 +208,13 @@ added: v2.1.0
208208
Prints a stack trace whenever synchronous I/O is detected after the first turn
209209
of the event loop.
210210

211-
### `--force-async-hooks-checks`
211+
### `--no-force-async-hooks-checks`
212212
<!-- YAML
213213
added: REPLACEME
214214
-->
215215

216-
Enables runtime checks for `async_hooks`. These can also be enabled dynamically
217-
by enabling one of the `async_hooks` hooks.
216+
Disables runtime checks for `async_hooks`. These will still be enabled
217+
dynamically when `async_hooks` is enabled.
218218

219219
### `--trace-events-enabled`
220220
<!-- YAML

doc/ayo.1

+3-3
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,9 @@ Print a stack trace whenever synchronous I/O is detected after the first turn
153153
of the event loop.
154154

155155
.TP
156-
.BR \-\-force\-async\-hooks\-checks
157-
Enables runtime checks for `async_hooks`. These can also be enabled dynamically
158-
by enabling one of the `async_hooks` hooks.
156+
.BR \-\-no\-force\-async\-hooks\-checks
157+
Disables runtime checks for `async_hooks`. These will still be enabled
158+
dynamically when `async_hooks` is enabled.
159159

160160
.TP
161161
.BR \-\-trace\-events\-enabled

src/env-inl.h

+10-3
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,13 @@ inline Environment::AsyncHooks::AsyncHooks(v8::Isolate* isolate)
6060
async_id_fields_(isolate, kUidFieldsCount) {
6161
v8::HandleScope handle_scope(isolate_);
6262

63+
// Always perform async_hooks checks, not just when async_hooks is enabled.
64+
// TODO(AndreasMadsen): Consider removing this for LTS releases.
65+
// See discussion in https://github.com/nodejs/node/pull/15454
66+
// When removing this, do it by reverting the commit. Otherwise the test
67+
// and flag changes won't be included.
68+
fields_[kCheck] = 1;
69+
6370
// kAsyncIdCounter should start at 1 because that'll be the id the execution
6471
// context during bootstrap (code that runs before entering uv_run()).
6572
async_id_fields_[AsyncHooks::kAsyncIdCounter] = 1;
@@ -101,9 +108,9 @@ inline v8::Local<v8::String> Environment::AsyncHooks::provider_string(int idx) {
101108
return providers_[idx].Get(isolate_);
102109
}
103110

104-
inline void Environment::AsyncHooks::force_checks() {
105-
// fields_ does not have the += operator defined
106-
fields_[kCheck] = fields_[kCheck] + 1;
111+
inline void Environment::AsyncHooks::no_force_checks() {
112+
// fields_ does not have the -= operator defined
113+
fields_[kCheck] = fields_[kCheck] - 1;
107114
}
108115

109116
inline void Environment::AsyncHooks::push_async_ids(double async_id,

src/env.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ class Environment {
435435

436436
inline v8::Local<v8::String> provider_string(int idx);
437437

438-
inline void force_checks();
438+
inline void no_force_checks();
439439

440440
inline void push_async_ids(double async_id, double trigger_async_id);
441441
inline bool pop_async_id(double async_id);

src/node.cc

+8-8
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ static bool syntax_check_only = false;
176176
static bool trace_deprecation = false;
177177
static bool throw_deprecation = false;
178178
static bool trace_sync_io = false;
179-
static bool force_async_hooks_checks = false;
179+
static bool no_force_async_hooks_checks = false;
180180
static bool track_heap_objects = false;
181181
static const char* eval_string = nullptr;
182182
static std::vector<std::string> preload_modules;
@@ -3969,8 +3969,8 @@ static void PrintHelp() {
39693969
" stderr\n"
39703970
" --trace-sync-io show stack trace when use of sync IO\n"
39713971
" is detected after the first tick\n"
3972-
" --force-async-hooks-checks\n"
3973-
" enables checks for async_hooks\n"
3972+
" --no-force-async-hooks-checks\n"
3973+
" disable checks for async_hooks\n"
39743974
" --trace-events-enabled track trace events\n"
39753975
" --trace-event-categories comma separated list of trace event\n"
39763976
" categories to record\n"
@@ -4096,7 +4096,7 @@ static void CheckIfAllowedInEnv(const char* exe, bool is_env,
40964096
"--trace-warnings",
40974097
"--redirect-warnings",
40984098
"--trace-sync-io",
4099-
"--force-async-hooks-checks",
4099+
"--no-force-async-hooks-checks",
41004100
"--trace-events-enabled",
41014101
"--trace-events-categories",
41024102
"--track-heap-objects",
@@ -4235,8 +4235,8 @@ static void ParseArgs(int* argc,
42354235
trace_deprecation = true;
42364236
} else if (strcmp(arg, "--trace-sync-io") == 0) {
42374237
trace_sync_io = true;
4238-
} else if (strcmp(arg, "--force-async-hooks-checks") == 0) {
4239-
force_async_hooks_checks = true;
4238+
} else if (strcmp(arg, "--no-force-async-hooks-checks") == 0) {
4239+
no_force_async_hooks_checks = true;
42404240
} else if (strcmp(arg, "--trace-events-enabled") == 0) {
42414241
trace_enabled = true;
42424242
} else if (strcmp(arg, "--trace-event-categories") == 0) {
@@ -4892,8 +4892,8 @@ inline int Start(Isolate* isolate, IsolateData* isolate_data,
48924892

48934893
env.set_abort_on_uncaught_exception(abort_on_uncaught_exception);
48944894

4895-
if (force_async_hooks_checks) {
4896-
env.async_hooks()->force_checks();
4895+
if (no_force_async_hooks_checks) {
4896+
env.async_hooks()->no_force_checks();
48974897
}
48984898

48994899
{

test/async-hooks/test-force-checks-flag.js

-25
This file was deleted.

test/async-hooks/test-no-assert-when-disabled.js

+1-9
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,10 @@
11
'use strict';
2-
// Flags: --expose-internals
2+
// Flags: --no-force-async-hooks-checks --expose-internals
33
const common = require('../common');
44

55
const async_hooks = require('async_hooks');
66
const internal = require('internal/process/next_tick');
77

8-
// In tests async_hooks dynamic checks are enabled by default. To verify
9-
// that no checks are enabled ordinarily disable the checks in this test.
10-
common.revert_force_async_hooks_checks();
11-
12-
// When async_hooks is diabled (or never enabled), the checks
13-
// should be disabled as well. This is important while async_hooks is
14-
// experimental and there are still critial bugs to fix.
15-
168
// Using undefined as the triggerAsyncId.
179
// Ref: https://github.com/nodejs/node/issues/14386
1810
// Ref: https://github.com/nodejs/node/issues/14381

test/common/index.js

-11
Original file line numberDiff line numberDiff line change
@@ -65,17 +65,6 @@ exports.projectDir = path.resolve(__dirname, '..', '..');
6565

6666
exports.buildType = process.config.target_defaults.default_configuration;
6767

68-
// Always enable async_hooks checks in tests
69-
{
70-
const async_wrap = process.binding('async_wrap');
71-
const { kCheck } = async_wrap.constants;
72-
async_wrap.async_hook_fields[kCheck] += 1;
73-
74-
exports.revert_force_async_hooks_checks = function() {
75-
async_wrap.async_hook_fields[kCheck] -= 1;
76-
};
77-
}
78-
7968
// If env var is set then enable async_hook hooks for all tests.
8069
if (process.env.NODE_TEST_WITH_ASYNC_HOOKS) {
8170
const destroydIdsList = {};

0 commit comments

Comments
 (0)