Skip to content

Commit 7c903ec

Browse files
addaleaxtargos
authored andcommitted
repl: disable blocking completions by default
It’s not okay for the REPL to be blocked for multiple seconds after entering `require('` because the completion is performing blocking fs operations on potentially huge directories. Turning the REPL completion function asynchronous would be the right thing to do here, but unfortunately the way the code is structured doesn’t play well with that (in particular, it breaks the preview feature). Therefore, disable these blocking calls by default. Refs: #33282 (comment) PR-URL: #36564 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
1 parent 3f33d0b commit 7c903ec

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

lib/repl.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,7 @@ function REPLServer(prompt,
298298
configurable: true
299299
});
300300

301+
this.allowBlockingCompletions = !!options.allowBlockingCompletions;
301302
this.useColors = !!options.useColors;
302303
this._domain = options.domain || domain.create();
303304
this.useGlobal = !!useGlobal;
@@ -1204,7 +1205,8 @@ function complete(line, callback) {
12041205
if (completeOn.length) {
12051206
filter = completeOn;
12061207
}
1207-
} else if (RegExpPrototypeTest(requireRE, line)) {
1208+
} else if (RegExpPrototypeTest(requireRE, line) &&
1209+
this.allowBlockingCompletions) {
12081210
// require('...<Tab>')
12091211
const extensions = ObjectKeys(this.context.require.extensions);
12101212
const indexes = ArrayPrototypeMap(extensions,
@@ -1265,7 +1267,8 @@ function complete(line, callback) {
12651267
if (!subdir) {
12661268
ArrayPrototypePush(completionGroups, _builtinLibs);
12671269
}
1268-
} else if (RegExpPrototypeTest(fsAutoCompleteRE, line)) {
1270+
} else if (RegExpPrototypeTest(fsAutoCompleteRE, line) &&
1271+
this.allowBlockingCompletions) {
12691272
[completionGroups, completeOn] = completeFSFunctions(line);
12701273
// Handle variable member lookup.
12711274
// We support simple chained expressions like the following (no function

test/parallel/test-repl-tab-complete.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,12 @@ function getNoResultsFunction() {
5151

5252
const works = [['inner.one'], 'inner.o'];
5353
const putIn = new ArrayStream();
54-
const testMe = repl.start('', putIn);
54+
const testMe = repl.start({
55+
prompt: '',
56+
input: putIn,
57+
output: process.stdout,
58+
allowBlockingCompletions: true
59+
});
5560

5661
// Some errors are passed to the domain, but do not callback
5762
testMe._domain.on('error', assert.ifError);

0 commit comments

Comments
 (0)