Skip to content

Uncatchable EINVAL when passing a 0-length array of buffers to FileHandle.writev #41910

@isker

Description

@isker

Version

16.13.2

Platform

Linux [myhostname] 3.10.0-1160.42.2.el7.x86_64 #1 SMP Tue Sep 7 14:49:57 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux

Subsystem

fs

What steps will reproduce the bug?

Invoke https://nodejs.org/api/fs.html#filehandlewritevbuffers-position with an empty array:

/tmp λ cat repro.mjs
import * as fs from 'fs';

try {
  const handle = await fs.promises.open('./out.txt', 'w');
  await handle.writev([]);
  await handle.close();
} catch (e) {
  console.error('caught', e);
}

console.log('done');

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

Unconditionally with the above reproduction. It also happens on macOS.

What is the expected behavior?

The resulting error should be caught and logged by the catch block.

Alternatively, this should not be an error at all. Writing no data with other FS functions does not result in errors.

What do you see instead?

The resulting error is uncatchable and kills the process.

/tmp λ node repro.mjs
node:internal/fs/promises:547
  const bytesWritten = (await binding.writeBuffers(handle.fd, buffers, position,
                                      ^

Error: EINVAL: invalid argument, write
    at writev (node:internal/fs/promises:547:39)
    at fsCall (node:internal/fs/promises:313:18)
    at FileHandle.writev (node:internal/fs/promises:182:12)
    at file:///tmp/repro.mjs:5:16 {
  errno: -22,
  code: 'EINVAL',
  syscall: 'write'
}

Additional information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    confirmed-bugIssues with confirmed bugs.fsIssues and PRs related to the fs subsystem / file system.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions