summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJoyee Cheung <joyeec9h3@gmail.com>2019-03-26 16:03:27 -0400
committerJoyee Cheung <joyeec9h3@gmail.com>2019-03-29 23:37:21 -0400
commit7aad63ba349d7b9b0eda4149d236ee66e5a26401 (patch)
tree7f6f08393640e77001b97948227ce1da6b33c848 /lib
parent58bf61524df078ed2563725aa5e982bed51a4853 (diff)
downloadandroid-node-v8-7aad63ba349d7b9b0eda4149d236ee66e5a26401.tar.gz
android-node-v8-7aad63ba349d7b9b0eda4149d236ee66e5a26401.tar.bz2
android-node-v8-7aad63ba349d7b9b0eda4149d236ee66e5a26401.zip
src: do not call into JS in the maxAsyncCallStackDepthChanged interrupt
If Debugger.setAsyncCallStackDepth is sent during bootstrap, we cannot immediately call into JS to enable the hooks, which could interrupt the JS execution of bootstrap. So instead we save the notification in the inspector agent if it's sent in the middle of bootstrap, and process the notification later here. Refs: https://github.com/nodejs/node/issues/26798 PR-URL: https://github.com/nodejs/node/pull/26935 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Eugene Ostroukhov <eostroukhov@google.com> Reviewed-By: Minwoo Jung <minwoo@nodesource.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/internal/bootstrap/node.js11
-rw-r--r--lib/internal/bootstrap/pre_execution.js18
-rw-r--r--lib/internal/main/worker_thread.js2
3 files changed, 19 insertions, 12 deletions
diff --git a/lib/internal/bootstrap/node.js b/lib/internal/bootstrap/node.js
index 5cc24980fa..abd88afce0 100644
--- a/lib/internal/bootstrap/node.js
+++ b/lib/internal/bootstrap/node.js
@@ -157,17 +157,6 @@ if (isMainThread) {
const { nativeHooks } = require('internal/async_hooks');
internalBinding('async_wrap').setupHooks(nativeHooks);
-// XXX(joyeecheung): this has to be done after the initial load of
-// `internal/async_hooks` otherwise `async_hooks` cannot require
-// `internal/async_hooks`. Investigate why.
-if (config.hasInspector) {
- const {
- enable,
- disable
- } = require('internal/inspector_async_hook');
- internalBinding('inspector').registerAsyncHook(enable, disable);
-}
-
const {
setupTaskQueue,
queueMicrotask
diff --git a/lib/internal/bootstrap/pre_execution.js b/lib/internal/bootstrap/pre_execution.js
index 20b362f213..ab7e169d7a 100644
--- a/lib/internal/bootstrap/pre_execution.js
+++ b/lib/internal/bootstrap/pre_execution.js
@@ -7,7 +7,7 @@ function prepareMainThreadExecution() {
// Patch the process object with legacy properties and normalizations
patchProcessObject();
setupTraceCategoryState();
-
+ setupInspectorHooks();
setupWarningHandler();
// Resolve the coverage directory to an absolute path, and
@@ -168,6 +168,21 @@ function setupTraceCategoryState() {
toggleTraceCategoryState(isTraceCategoryEnabled('node.async_hooks'));
}
+function setupInspectorHooks() {
+ // If Debugger.setAsyncCallStackDepth is sent during bootstrap,
+ // we cannot immediately call into JS to enable the hooks, which could
+ // interrupt the JS execution of bootstrap. So instead we save the
+ // notification in the inspector agent if it's sent in the middle of
+ // bootstrap, and process the notification later here.
+ if (internalBinding('config').hasInspector) {
+ const {
+ enable,
+ disable
+ } = require('internal/inspector_async_hook');
+ internalBinding('inspector').registerAsyncHook(enable, disable);
+ }
+}
+
// In general deprecations are intialized wherever the APIs are implemented,
// this is used to deprecate APIs implemented in C++ where the deprecation
// utitlities are not easily accessible.
@@ -361,5 +376,6 @@ module.exports = {
initializeFrozenIntrinsics,
loadPreloadModules,
setupTraceCategoryState,
+ setupInspectorHooks,
initializeReport
};
diff --git a/lib/internal/main/worker_thread.js b/lib/internal/main/worker_thread.js
index fd3502e078..71babafd0e 100644
--- a/lib/internal/main/worker_thread.js
+++ b/lib/internal/main/worker_thread.js
@@ -6,6 +6,7 @@
const {
patchProcessObject,
setupCoverageHooks,
+ setupInspectorHooks,
setupWarningHandler,
setupDebugEnv,
initializeDeprecations,
@@ -43,6 +44,7 @@ const {
const publicWorker = require('worker_threads');
patchProcessObject();
+setupInspectorHooks();
setupDebugEnv();
const debug = require('internal/util/debuglog').debuglog('worker');