From 3eea43af074e129963a3398dc91ce22a589f8a13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Reis?= Date: Tue, 30 Jul 2019 07:45:59 +0100 Subject: [PATCH] repl: close file descriptor of history file PR-URL: https://github.com/nodejs/node/pull/28858 Reviewed-By: Rich Trott Reviewed-By: Colin Ihrig --- lib/internal/repl/history.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lib/internal/repl/history.js b/lib/internal/repl/history.js index dd3ea850954936..5d90b40e0041c7 100644 --- a/lib/internal/repl/history.js +++ b/lib/internal/repl/history.js @@ -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() {