Skip to content

feat(DEP0207): migrate HTTP/2 'aborted' listeners to 'close' - #580

Open
FrustratedBoy420 wants to merge 1 commit into
nodejs:mainfrom
FrustratedBoy420:feat/dep0207-http2-aborted
Open

FrustratedBoy420 wants to merge 1 commit into
nodejs:mainfrom
FrustratedBoy420:feat/dep0207-http2-aborted

Conversation

@FrustratedBoy420

Copy link
Copy Markdown

Closes #558

What it does

Adds the http2-aborted-to-close recipe for DEP0207. It applies one chosen strategy, "run this handler when the writable side did not finish before the stream closed", which matches the write-side example in the DEP0207 docs:

 server.on('stream', (stream) => {
-  stream.on('aborted', () => {
-    recordIncompleteResponse();
+  stream.on('close', () => {
+    if (!stream.writableFinished) {
+      recordIncompleteResponse();
+    }
   });
 });

Scope follows the issue:

  • Resolved streams only: the first parameter of a 'stream' listener on a createServer() / createSecureServer() server, and session.request() results on a connect() session. Works with http2 and node:http2 from require or import (default, namespace, named and aliased).
  • Inline listeners with no parameters only, registered as a statement (on, once, addListener, prependListener, prependOnceListener). Block and expression bodies are both handled.
  • Reported with file:line:col, not rewritten: .aborted property reads, named listeners or listeners with parameters, and every 'aborted' listener on a stream whose 'aborted' listeners are also removed, counted or listed (off, removeListener, removeAllListeners, listeners, rawListeners, listenerCount).
  • Not touched: the compatibility API (createServer((req, res) => …)) and read-side 'error' handling.

Tests

9 cases: CJS server, ESM aliased createSecureServer with once and a function listener, client request() with an expression body, chained createServer().on('stream', …) with 2-space indentation, TypeScript typed parameters, and four "unchanged" cases (named/parameterised listeners plus a .aborted read, removeAllListeners('aborted'), the compat API, and a file without http2).

npm test in the recipe, biome lint and tsc --noEmit pass.

Runtime check and a question

The issue asks to validate the rewrite against normal completion, peer reset, local destruction, and writes ended but not finished. I ran those four cases on Node.js 25 (the only version I have locally), recording whether 'aborted' fired and whether !writableFinished was true at 'close':

Case 'aborted' close && !writableFinished
normal completion false false
peer reset mid-response true false
local destroy() true true
end() called, not finished, then peer reset false true

On Node 25 the new pattern misses a peer reset, because the writable side is already finished by 'close'. As far as I can tell, nodejs/node#63249 (Node 27) changes this reset handling, and that is why the docs recommend this pattern, but I could not test Node 27 here. The README says to run the codemod when moving to Node.js 27. Could someone confirm the peer-reset row on 27?

AI assistance

I used Claude Code (claude-opus-5-5) to help write the transform, tests and README, and to run the runtime check above. I reviewed every line and can explain it. The commit has an Assisted-by trailer, following the OpenJS AI coding assistants policy.

Add the http2-aborted-to-close recipe. It applies one chosen strategy
("run this handler when the writable side did not finish"): an inline
'aborted' listener with no parameters on a locally resolved
Http2Stream becomes a 'close' listener wrapped in
`if (!stream.writableFinished)`.

Resolved streams: the first parameter of a 'stream' listener on a
createServer()/createSecureServer() server, and session.request()
results on a connect() session.

Reported, not rewritten: .aborted property reads, named listeners or
listeners with parameters, and streams whose 'aborted' listeners are
removed, counted or listed. The compatibility API and read-side
'error' handling are left alone.

Closes nodejs#558

Assisted-by: Claude Code (claude-opus-5-5)
Copilot AI balanced review requested due to automatic review settings November 23, 2026 19:14

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(DEP0207): migrate HTTP/2 abort handling to standard stream events

2 participants