nodejs / nodejs/node

Nonsense UNKNOWN error when writing large buffers with fs.writev

Open
#40,779 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

fs
Dominant language
JavaScript
Stars
122k
Forks
37.3k
Avg merge
4d 2h
Merged PRs (30d)
283

Description

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 c4e7dca8f30ff89b42e96fb8819558ed518a72dd. 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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at fs.writevSync in fs.js and compare its argument handling with the fs.write validation referenced by commit c4e7dca8f30ff89b42e96fb8819558ed518a72dd. Reproduce the large-buffer case on Linux, then determine whether the finished behavior should reject the request with a proper error before the syscall or support the larger buffer through libuv.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, node.js
Domain
backend, operating-systems
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.