mirror of
https://github.com/nodejs/node.git
synced 2026-10-28 10:15:07 +08:00
An fd released with closeSync() can be reused by background I/O before FileHandle.close() runs in the thread pool, so closing it can succeed. Construct the handle around a high invalid fd to keep the native EBADF rejection path deterministic. Refs: https://github.com/nodejs/reliability/blob/main/reports/2026-10-15.md Signed-off-by: Filip Skokan <panva.ip@gmail.com> Assisted-by: Codex PR-URL: https://github.com/nodejs/node/pull/66750 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Gürgün Dayıoğlu <hey@gurgun.day> Reviewed-By: Daijiro Wachi <daijiro.wachi@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Ulises Gascón <ulisesgascongonzalez@gmail.com>
22 lines
684 B
JavaScript
22 lines
684 B
JavaScript
// Flags: --expose-internals
|
|
'use strict';
|
|
const common = require('../common');
|
|
const assert = require('assert');
|
|
const { internalBinding } = require('internal/test/binding');
|
|
const { FileHandle } = require('internal/fs/promises');
|
|
const { FileHandle: NativeFileHandle } = internalBinding('fs');
|
|
|
|
// Test that closing a FileHandle with an invalid fd fails with EBADF.
|
|
// Use a high invalid fd so background I/O cannot reuse it before close runs.
|
|
|
|
(async function() {
|
|
const fh = common.runWithInvalidFD(
|
|
(fd) => new FileHandle(new NativeFileHandle(fd)),
|
|
);
|
|
|
|
await assert.rejects(() => fh.close(), {
|
|
code: 'EBADF',
|
|
syscall: 'close'
|
|
});
|
|
})().then(common.mustCall());
|