Skip to content

vfs: fs.writeFileSync(fd, ...) does not dispatch virtual file descriptors #64164

Description

@trivikr

Version

main

Platform

macOS 26.5.0

Subsystem

vfs

What steps will reproduce the bug?

import fs from 'node:fs';
import os from 'node:os';
import path from 'node:path';
import vfs from 'node:vfs';

const mountPoint = fs.mkdtempSync(path.join(os.tmpdir(), 'vfs-mount-'));

const mounted = vfs
  .create({ emitExperimentalWarning: false })
  .mount(mountPoint);

try {
  const file = path.join(mountPoint, 'file.txt');

  fs.writeFileSync(file, 'abcdef');

  const fd = fs.openSync(file, 'r+');

  try {
    fs.writeFileSync(fd, 'XY');
    console.log(fs.readFileSync(file, 'utf8'));
  } catch (err) {
    console.log('threw:', err.code, err.syscall);
  } finally {
    fs.closeSync(fd);
  }
} finally {
  mounted.unmount();
  fs.rmSync(mountPoint, { recursive: true, force: true });
}

How often does it reproduce? Is there a required condition?

Always

What is the expected behavior? Why is that the expected behavior?

XYcdef

Native fs.writeFileSync(fd, data) writes through the already-open descriptor at its current file position, so virtual fds should be dispatched the same way as fs.readFileSync(fd) and fs.readSync(fd, ...).

What do you see instead?

throws EBADF with syscall write.

Additional information

No response

Metadata

Metadata

Assignees

Labels

vfsIssues and PRs related to the virtual filesystem subsystem.

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions