Skip to content

Commit

Permalink
repl: close file descriptor of history file
Browse files Browse the repository at this point in the history
PR-URL: #28858
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
  • Loading branch information
joaocgreis authored and Trott committed Aug 11, 2019
1 parent eadc385 commit 3eea43a
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions lib/internal/repl/history.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit 3eea43a

Please sign in to comment.