repl: close file descriptor of history file

PR-URL: https://github.com/nodejs/node/pull/28858
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
This commit is contained in:
João Reis 2019-07-30 07:45:59 +01:00 committed by Rich Trott
parent eadc3850fe
commit 3eea43af07

View File

@ -93,6 +93,7 @@ function setupHistory(repl, historyPath, ready) {
fs.ftruncate(hnd, 0, (err) => {
repl._historyHandle = hnd;
repl.on('line', online);
repl.once('exit', onexit);
// Reading the file data out erases it
repl.once('flushHistory', function() {
@ -137,6 +138,15 @@ function setupHistory(repl, historyPath, ready) {
}
}
}
function onexit() {
if (repl._flushing) {
repl.once('flushHistory', onexit);
return;
}
repl.off('line', online);
fs.close(repl._historyHandle, () => {});
}
}
function _replHistoryMessage() {