Skip to content

HTTP/2 GET/HEAD requests with a body fail with ERR_STREAM_WRITE_AFTER_END #5057

@trivikr

Description

@trivikr

Bug Description

HTTP/2 requests with a body on GET are broken, and the same code path also affects HEAD when a body is provided.

Reproducible By

Run the following in root

import { createServer } from "node:http2";
import { H2CClient } from "./index.js";

const server = createServer((req, res) => {
  req.resume();
  req.on("end", () => res.end("ok"));
});

server.listen(0, async () => {
  const client = new H2CClient(`http://localhost:${server.address().port}/`);
  client.request({ path: "/", method: "GET", body: "hello" }, (err) => {
    console.error(err);
    client.destroy();
    server.close();
  });
});

Observe that the request fails with ERR_STREAM_WRITE_AFTER_END.

Expected Behavior

A GET or HEAD request with a provided body should not create an already-ended HTTP/2 stream.

Logs & Screenshots

Error [ERR_STREAM_WRITE_AFTER_END]: write after end
    at _write (node:internal/streams/writable:487:11)
    at Writable.write (node:internal/streams/writable:508:10)
    at writeBuffer (/Users/trivikram/workspace/undici/lib/dispatcher/client-h2.js:859:16)
    at writeBodyH2 (/Users/trivikram/workspace/undici/lib/dispatcher/client-h2.js:792:7)
    at writeH2 (/Users/trivikram/workspace/undici/lib/dispatcher/client-h2.js:675:5)
    at Object.write (/Users/trivikram/workspace/undici/lib/dispatcher/client-h2.js:157:14)
    at _resume (/Users/trivikram/workspace/undici/lib/dispatcher/client.js:656:50)
    at resume (/Users/trivikram/workspace/undici/lib/dispatcher/client.js:574:3)
    at Client.<computed> (/Users/trivikram/workspace/undici/lib/dispatcher/client.js:293:31)
    at /Users/trivikram/workspace/undici/lib/dispatcher/client.js:518:22 {
  code: 'ERR_STREAM_WRITE_AFTER_END'
}

Environment

Node v24.14.1
undici 8.1.0

Additional context

N/A

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions