From 2073a78e07346387893a70d0a6b01550a6580e46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Reis?= Date: Tue, 30 Jul 2019 07:45:31 +0100 Subject: [PATCH] fs: close file descriptor of promisified truncate PR-URL: https://github.com/nodejs/node/pull/28858 Reviewed-By: Rich Trott Reviewed-By: Colin Ihrig --- lib/internal/fs/promises.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/internal/fs/promises.js b/lib/internal/fs/promises.js index d653724474f..31eaeef2846 100644 --- a/lib/internal/fs/promises.js +++ b/lib/internal/fs/promises.js @@ -305,7 +305,8 @@ async function rename(oldPath, newPath) { } async function truncate(path, len = 0) { - return ftruncate(await open(path, 'r+'), len); + const fd = await open(path, 'r+'); + return ftruncate(fd, len).finally(fd.close.bind(fd)); } async function ftruncate(handle, len = 0) {