mirror of
https://github.com/nodejs/node.git
synced 2025-12-28 07:50:41 +00:00
repl: fix eval errors thrown after close throwing ERR_USE_AFTER_CLOSE
prevent incorrect throws of `ERR_USE_AFTER_CLOSE` errors when the eval function of a repl server returns an error after the repl server has been closed PR-URL: https://github.com/nodejs/node/pull/58791 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
This commit is contained in:
parent
d824914e61
commit
9fe3316280
@ -748,7 +748,9 @@ function REPLServer(prompt,
|
||||
process.emit('uncaughtException', e);
|
||||
self.clearBufferedCommand();
|
||||
self.lines.level = [];
|
||||
self.displayPrompt();
|
||||
if (!self.closed) {
|
||||
self.displayPrompt();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
if (errStack === '') {
|
||||
@ -778,7 +780,9 @@ function REPLServer(prompt,
|
||||
self.output.write(errStack);
|
||||
self.clearBufferedCommand();
|
||||
self.lines.level = [];
|
||||
self.displayPrompt();
|
||||
if (!self.closed) {
|
||||
self.displayPrompt();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
45
test/parallel/test-repl-eval-error-after-close.js
Normal file
45
test/parallel/test-repl-eval-error-after-close.js
Normal file
@ -0,0 +1,45 @@
|
||||
'use strict';
|
||||
|
||||
const common = require('../common');
|
||||
const repl = require('node:repl');
|
||||
const stream = require('node:stream');
|
||||
const assert = require('node:assert');
|
||||
|
||||
// This test checks that an eval function returning an error in its callback
|
||||
// after the repl server has been closed doesn't cause an ERR_USE_AFTER_CLOSE
|
||||
// error to be thrown (reference: https://github.com/nodejs/node/issues/58784)
|
||||
|
||||
(async () => {
|
||||
const close$ = Promise.withResolvers();
|
||||
const eval$ = Promise.withResolvers();
|
||||
|
||||
const input = new stream.PassThrough();
|
||||
const output = new stream.PassThrough();
|
||||
|
||||
const replServer = repl.start({
|
||||
input,
|
||||
output,
|
||||
eval(_cmd, _context, _file, cb) {
|
||||
close$.promise.then(() => {
|
||||
cb(new Error('Error returned from the eval callback'));
|
||||
eval$.resolve();
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
let outputStr = '';
|
||||
output.on('data', (data) => {
|
||||
outputStr += data;
|
||||
});
|
||||
|
||||
input.write('\n');
|
||||
|
||||
replServer.close();
|
||||
close$.resolve();
|
||||
|
||||
process.on('uncaughtException', common.mustNotCall());
|
||||
|
||||
await eval$.promise;
|
||||
|
||||
assert.match(outputStr, /Uncaught Error: Error returned from the eval callback/);
|
||||
})().then(common.mustCall());
|
||||
Loading…
Reference in New Issue
Block a user