Skip to content

node:http: the request of a pipelined response destroyed while queued never emits 'aborted', 'error' or 'close' #43512

Closed

Description

@robobun

What happens

Two requests arrive pipelined on one connection. The 'request' listener destroys the second response while it is still queued behind the first one. The second request then never emits 'aborted', 'error' or 'close'. A consumer that waits for the end of that request (for await, stream.finished, a body parser) never settles.

Repro

const http = require("node:http");
const net = require("node:net");
const events = [];
const server = http.createServer((req, res) => {
  if (req.url === "/1") return void setTimeout(() => res.end("one"), 50);
  req.on("aborted", () => events.push("req2 aborted"));
  req.on("error", e => events.push("req2 error:" + e.code));
  req.on("close", () => events.push("req2 close"));
  res.on("close", () => events.push("res2 close"));
  req.resume();
  res.destroy(); // res2 is still queued behind res1
});
server.listen(0, "127.0.0.1", () => {
  const c = net.connect(server.address().port, "127.0.0.1");
  c.on("error", () => {});
  c.write("GET /1 HTTP/1.1\r\nHost: a\r\n\r\nPOST /2 HTTP/1.1\r\nHost: a\r\nContent-Length: 10\r\n\r\nabc");
  setTimeout(() => c.destroy(), 500);
  setTimeout(() => { console.log(events.join(", ")); server.close(); }, 1000);
});
  • Node v26.3.0: res2 close, req2 aborted, req2 error:ECONNRESET, req2 close
  • Bun 1.4.3 (canary 367d939): res2 close

Cause (from a read of the code)

advanceResponsePipeline in src/js/node/_http_server.ts shifts the destroyed response out of socket[kPipelinedResponses] and then destroys the socket (the res.destroyed || !handle branch). It does not touch res.req. The response never became socket._httpMessage, so NodeHTTPServerSocket#onClose does not find the request. abortQueuedPipelinedResponses does not find it either, because the response is no longer in the queue. The next branch (startPipelinedResponse returns false) has the same gap.

abortQueuedPipelinedResponses already shows how such a request is aborted: req.destroy(new ConnResetException("aborted")) when the request has an 'error' listener, req.destroy() otherwise.

Activity

  1. robobun commented on Sep 19, 2026

    @robobun
    CollaboratorAuthor

    Reproduced: the repro prints only res2 close on Bun 1.4.3, Node prints the four events.
    Fix: #43549 covers this case (verified with a test on that branch). Test branch: main...robobun/303b7617/pipelined-destroyed-res-abort-req

  2. added a commit that references this issue on Sep 26, 2026
    5d5f03f
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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions