Skip to content

Nonsense UNKNOWN error when writing large buffers with fs.writev #40779

@zbjornson

Description

@zbjornson

Version

14.18.1

Platform

Linux ops 5.11.0-1021-gcp #23~20.04.1-Ubuntu SMP Fri Oct 1 19:04:32 UTC 2021 x86_64 x86_64 x86_64 GNU/Linu

Subsystem

fs

What steps will reproduce the bug?

const fs = require("fs");
const fd = fs.openSync("./test.dat", fs.constants.O_WRONLY | fs.constants.O_CREAT, 0o666);
const bufs = [Buffer.alloc(0x7FFFFFFF + 1)];
fs.writevSync(fd, bufs, 0);

This throws

Uncaught Error: UNKNOWN: unknown error, write
    at Object.writevSync (fs.js:749:3) {
  errno: -2147483648,
  syscall: 'write',
  code: 'UNKNOWN'
}

That errno is 0x7fffffff + 1 wrapped around.

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

Always.

What is the expected behavior?

Should either work, since pwritev(2) works (I don't know if it has a limit less than SSIZE_MAX), or report a proper error before making the syscall. I did the latter recently for fs.write in c4e7dca. It would be nice if large files actually worked, but the best fix for that would require a new libuv function.

What do you see instead?

No response

Additional information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    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