2020-01-16 21:12:07 +00:00
|
|
|
'use strict';
|
|
|
|
const common = require('../common');
|
|
|
|
const assert = require('assert');
|
|
|
|
const fs = require('fs').promises;
|
|
|
|
|
|
|
|
(async () => {
|
|
|
|
const filehandle = await fs.open(__filename);
|
|
|
|
|
|
|
|
assert.notStrictEqual(filehandle.fd, -1);
|
|
|
|
await filehandle.close();
|
|
|
|
assert.strictEqual(filehandle.fd, -1);
|
|
|
|
|
|
|
|
// Open another file handle first. This would typically receive the fd
|
|
|
|
// that `filehandle` previously used. In earlier versions of Node.js, the
|
|
|
|
// .stat() call would then succeed because it still used the original fd;
|
|
|
|
// See https://github.com/nodejs/node/issues/31361 for more details.
|
|
|
|
const otherFilehandle = await fs.open(process.execPath);
|
|
|
|
|
2023-10-23 17:55:50 +00:00
|
|
|
await assert.rejects(() => filehandle.stat(), {
|
2020-01-16 21:12:07 +00:00
|
|
|
code: 'EBADF',
|
|
|
|
syscall: 'fstat'
|
|
|
|
});
|
|
|
|
|
|
|
|
await otherFilehandle.close();
|
|
|
|
})().then(common.mustCall());
|