Skip to content

Commit 9347db1

Browse files
authored
test: deflake test-filehandle-close
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: #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>
1 parent 4e75b71 commit 9347db1

1 file changed

Lines changed: 9 additions & 5 deletions

File tree

‎test/parallel/test-filehandle-close.js‎

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
1+
// Flags: --expose-internals
12
'use strict';
23
const common = require('../common');
34
const assert = require('assert');
4-
const fs = require('fs');
5+
const { internalBinding } = require('internal/test/binding');
6+
const { FileHandle } = require('internal/fs/promises');
7+
const { FileHandle: NativeFileHandle } = internalBinding('fs');
58

6-
// Test that using FileHandle.close to close an already-closed fd fails
7-
// with EBADF.
9+
// Test that closing a FileHandle with an invalid fd fails with EBADF.
10+
// Use a high invalid fd so background I/O cannot reuse it before close runs.
811

912
(async function() {
10-
const fh = await fs.promises.open(__filename);
11-
fs.closeSync(fh.fd);
13+
const fh = common.runWithInvalidFD(
14+
(fd) => new FileHandle(new NativeFileHandle(fd)),
15+
);
1216

1317
await assert.rejects(() => fh.close(), {
1418
code: 'EBADF',

0 commit comments

Comments
 (0)