node/test/parallel/test-fs-open-no-close.js
Nitzan Uziely f9447b71a6
fs: fix rmsync error swallowing
fix rmsync swallowing errors instead of throwing them.

fixes: https://github.com/nodejs/node/issues/38683
fixes: https://github.com/nodejs/node/issues/34580

PR-URL: https://github.com/nodejs/node/pull/38684
Fixes: https://github.com/nodejs/node/issues/38683
Fixes: https://github.com/nodejs/node/issues/34580
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Darshan Sen <raisinten@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2021-05-25 07:18:05 -07:00

32 lines
671 B
JavaScript

'use strict';
// Refs: https://github.com/nodejs/node/issues/34266
// Failing to close a file should not keep the event loop open.
const common = require('../common');
const assert = require('assert');
const fs = require('fs');
const debuglog = (arg) => {
console.log(new Date().toLocaleString(), arg);
};
const tmpdir = require('../common/tmpdir');
tmpdir.refresh();
let openFd;
fs.open(`${tmpdir.path}/dummy`, 'wx+', common.mustCall((err, fd) => {
debuglog('fs open() callback');
assert.ifError(err);
openFd = fd;
}));
debuglog('waiting for callback');
process.on('beforeExit', common.mustCall(() => {
if (openFd) {
fs.closeSync(openFd);
}
}));