From be464528deb1844c02b5e294960a9efc9a7d2ec7 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Thu, 9 Jan 2020 11:24:23 +0100 Subject: [PATCH 1/2] fs: add missing HandleScope to FileHandle.close Fixes: https://github.com/nodejs/node/issues/31202 --- src/node_file.cc | 1 + test/parallel/test-filehandle-close.js | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) create mode 100644 test/parallel/test-filehandle-close.js diff --git a/src/node_file.cc b/src/node_file.cc index 769d76670180fa..c341962cc60dbf 100644 --- a/src/node_file.cc +++ b/src/node_file.cc @@ -301,6 +301,7 @@ MaybeLocal FileHandle::ClosePromise() { close->file_handle()->AfterClose(); Isolate* isolate = close->env()->isolate(); if (req->result < 0) { + HandleScope handle_scope(isolate); close->Reject(UVException(isolate, req->result, "close")); } else { close->Resolve(); diff --git a/test/parallel/test-filehandle-close.js b/test/parallel/test-filehandle-close.js new file mode 100644 index 00000000000000..6ea79c10237815 --- /dev/null +++ b/test/parallel/test-filehandle-close.js @@ -0,0 +1,17 @@ +'use strict'; +const common = require('../common'); +const assert = require('assert'); +const fs = require("fs"); + +// Test that using FileHandle.close to close an already-closed fd fails +// with EBADF. + +(async function() { + const fh = await fs.promises.open(__filename); + fs.closeSync(fh.fd); + + assert.rejects(() => fh.close(), { + code: 'EBADF', + syscall: 'close' + }); +})().then(common.mustCall()); From 521398133f94d3c1dbe80abd6157cab54cdabab0 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Thu, 9 Jan 2020 16:05:57 +0100 Subject: [PATCH 2/2] fixup! fs: add missing HandleScope to FileHandle.close --- test/parallel/test-filehandle-close.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/parallel/test-filehandle-close.js b/test/parallel/test-filehandle-close.js index 6ea79c10237815..457b06a486f90f 100644 --- a/test/parallel/test-filehandle-close.js +++ b/test/parallel/test-filehandle-close.js @@ -1,7 +1,7 @@ 'use strict'; const common = require('../common'); const assert = require('assert'); -const fs = require("fs"); +const fs = require('fs'); // Test that using FileHandle.close to close an already-closed fd fails // with EBADF.