Skip to content

Commit 3eea43a

Browse files
joaocgreisTrott
authored andcommitted
repl: close file descriptor of history file
PR-URL: #28858 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
1 parent eadc385 commit 3eea43a

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

lib/internal/repl/history.js

+10
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ function setupHistory(repl, historyPath, ready) {
9393
fs.ftruncate(hnd, 0, (err) => {
9494
repl._historyHandle = hnd;
9595
repl.on('line', online);
96+
repl.once('exit', onexit);
9697

9798
// Reading the file data out erases it
9899
repl.once('flushHistory', function() {
@@ -137,6 +138,15 @@ function setupHistory(repl, historyPath, ready) {
137138
}
138139
}
139140
}
141+
142+
function onexit() {
143+
if (repl._flushing) {
144+
repl.once('flushHistory', onexit);
145+
return;
146+
}
147+
repl.off('line', online);
148+
fs.close(repl._historyHandle, () => {});
149+
}
140150
}
141151

142152
function _replHistoryMessage() {

0 commit comments

Comments
 (0)