Skip to content

request: highWaterMark: NaN bypasses validation and throws ERR_INVALID_ARG_VALUE later #5061

@trivikr

Description

@trivikr

Bug Description

request() does not reject highWaterMark: NaN during option validation.

Reproducible By

import { createServer } from "node:http";
import { Client } from "undici";

const server = createServer((req, res) => {
  console.log("server: received request");
  res.writeHead(200, { "content-type": "text/plain" });
  res.end("hello");
});

server.listen(0, () => {
  const client = new Client(`http://localhost:${server.address().port}`);

  client.request(
    {
      path: "/",
      method: "GET",
      highWaterMark: Number.NaN,
    },
    (err, data) => {
      console.log("callback err:", {
        name: err?.name,
        code: err?.code,
        message: err?.message,
      });
      console.log("callback data exists:", !!data);

      client.close();
      server.close();
    },
  );
});

Expected Behavior

Undici should reject highWaterMark: NaN up front during request option validation, consistently with other invalid highWaterMark values such as strings and negative numbers.

The error should be InvalidArgumentError('invalid highWaterMark'), and the request should not proceed far enough to create the response body stream.

Logs & Screenshots

server: received request
callback err: {
  name: 'TypeError',
  code: 'ERR_INVALID_ARG_VALUE',
  message: "The property 'options.highWaterMark' is invalid. Received NaN"
}
callback data exists: true

Environment

macOS 26.4.1
Node v24.14.1
undici v8.1.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions