Skip to content

Uncatchable AssertionError: assert(!this.paused) on socket end #5360

Description

@andreypopp

Description

If the consumer doesn't read the body immediately, the HTTP/1 parser pauses under
backpressure. When the socket ends (FIN), onHttpSocketEnd calls parser.finish(),
which asserts !this.paused. Since the parser is paused, this throws an uncatchable
AssertionError from the socket 'end' handler and crashes the process.

AssertionError [ERR_ASSERTION]: assert(!this.paused)
    at Parser.finish (.../undici/lib/dispatcher/client-h1.js:374:5)
    at Socket.onHttpSocketEnd (.../undici/lib/dispatcher/client-h1.js:951:30)

onHttpSocketEnd doesn't check parser.paused before calling finish().

Reproduction (minimised with Claude Code)

import { createServer } from "node:net";
import { fetch } from "undici";

const BODY = Buffer.alloc(64 * 1024, 0x61);

const server = createServer((sock) => {
  sock.once("data", () => {
    sock.write(
      "HTTP/1.1 200 OK\r\n" +
        `Content-Length: ${BODY.length}\r\n` +
        "Connection: close\r\n\r\n",
    );
    sock.write(BODY);
    sock.end(); // FIN
  });
});

server.listen(0, "127.0.0.1", async () => {
  const { port } = server.address();
  const res = await fetch(`http://127.0.0.1:${port}/`);
  void res; // never read the body -> parser pauses -> crash on FIN
  await new Promise((r) => setTimeout(r, 1000));
  console.log("no crash"); // never reached
});

The 64 KiB body is the body highWaterMark — the smallest size that pauses while still
arriving in one socket read, which makes this deterministic. It's not a fixed value:
the real trigger is "paused with the read buffer drained when FIN arrives," so the
size is network-dependent (intermittent across sizes over a real connection).

Expected vs actual

  • Expected: clean end, or a catchable error. A peer closing a non-keep-alive
    response under backpressure shouldn't crash the process.
  • Actual: uncatchable AssertionError, exit code 1.

Environment

  • undici 8.3.0 (and current main)
  • Node.js v22.22.2, Linux

Activity

  1. added
    bug
    on Jun 5, 2026
  2. added a commit that references this issue on Jun 6, 2026
    2aa5739
  3. AliMahmoudDev commented on Jun 7, 2026

    @AliMahmoudDev
    Contributor

    nice catch. the fix should be straightforward — in onHttpSocketEnd (client-h1.js:951), check parser.paused before calling parser.finish(). if paused, resume the parser first so it drains the internal buffer, then finish.

    alternatively, wrapping the parser.finish() call in a try/catch or guard would prevent the uncatchable throw from the socket event handler, but properly resuming before finishing seems like the cleaner fix.

  4. Azlond commented on Jul 1, 2026

    @Azlond

    We started seeing this error in Node 24.17, and it still occurs in 24.18, which both use undici@7. Any chance the fix could get backported to the v7 release?
    https://github.com/nodejs/undici/blame/v7.x/lib/dispatcher/client-h1.js#L367

  5. 2 remaining items

  6. added a commit that references this issue on Sep 19, 2026
    81b0ec8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions