Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
stop bootstrap buffer as soon as usercode runs
  • Loading branch information
guybedford committed Oct 6, 2019
commit ae46f454877677e26e09b2793d8581556ab72650
18 changes: 11 additions & 7 deletions lib/internal/async_hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -289,8 +289,8 @@ function bufferBootstrapHooks() {
}
}

function clearBootstrapHooksBuffer() {
if (!bootstrapBuffer)
function stopBootstrapHooksBuffer() {
if (!bootstrapHooks)
return;
async_hook_fields[kInit]--;
async_hook_fields[kBefore]--;
Expand All @@ -299,19 +299,21 @@ function clearBootstrapHooksBuffer() {
async_hook_fields[kPromiseResolve]--;
async_hook_fields[kTotals] -= 5;
active_hooks.array.splice(active_hooks.array.indexOf(bootstrapHooks), 1);
bootstrapHooks = null;
if (async_hook_fields[kTotals] === 0) {
disableHooks();
// Flush microtasks to ensure disable has run.
process._tickCallback();
}
const _bootstrapBuffer = bootstrapBuffer;
}

function clearBootstrapHooksBuffer() {
if (bootstrapHooks)
stopBootstrapHooksBuffer();
bootstrapBuffer = null;
bootstrapHooks = null;
return _bootstrapBuffer;
}

function emitBootstrapHooksBuffer() {
const bootstrapBuffer = clearBootstrapHooksBuffer();
if (!bootstrapBuffer || async_hook_fields[kTotals] === 0) {
return;
}
Expand All @@ -331,6 +333,7 @@ function emitBootstrapHooksBuffer() {
break;
}
}
bootstrapBuffer = null;
}

let wantPromiseHook = false;
Expand Down Expand Up @@ -573,5 +576,6 @@ module.exports = {
},
bufferBootstrapHooks,
clearBootstrapHooksBuffer,
emitBootstrapHooksBuffer
emitBootstrapHooksBuffer,
stopBootstrapHooksBuffer
};
8 changes: 5 additions & 3 deletions lib/internal/modules/esm/module_job.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ const { ModuleWrap } = internalBinding('module_wrap');
const { decorateErrorStack } = require('internal/util');
const { getOptionValue } = require('internal/options');
const assert = require('internal/assert');
const { clearBootstrapHooksBuffer } = require('internal/async_hooks');
const { clearBootstrapHooksBuffer, stopBootstrapHooksBuffer } =
require('internal/async_hooks');
const resolvedPromise = SafePromise.resolve();

function noop() {}
Expand Down Expand Up @@ -107,13 +108,14 @@ class ModuleJob {
const module = await this.instantiate();
const timeout = -1;
const breakOnSigint = false;
if (this.isMain)
stopBootstrapHooksBuffer();
const output = {
module,
result: module.evaluate(timeout, breakOnSigint)
};
if (this.isMain) {
if (this.isMain)
clearBootstrapHooksBuffer();
}
return output;
}
}
Expand Down