GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — http: emit error on aborted ServerResponse by trivikr · Pull Request #63448 · nodejs/node

Conversation

@trivikr

@trivikr trivikr commented May 20, 2026

Copy link
Copy Markdown
Member

This updates ServerResponse socket-close handling so an ended response that
never emitted finish is marked with ECONNRESET and emits error before
close when an error listener is present.

A regression test covers the case where the request socket is destroyed before
a deferred res.end(), which previously emitted only close.

Fixes: #50656


Assisted-by: openai:gpt-5.5

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@trivikr
http: emit error on aborted ServerResponse
0805ecb
Emit an error when a ServerResponse is closed after end() but before
the finish event is emitted.

Fixes: nodejs#50656

Signed-off-by: Kamat, Trivikram <[email protected]>
Assisted-by: openai:gpt-5.5
@nodejs-github-bot

nodejs-github-bot commented May 20, 2026

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/http
  • @nodejs/net
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@nodejs-github-bot nodejs-github-bot added http Issues and PRs related to the http subsystem. needs-ci PRs that need a full CI run. labels May 20, 2026
trivikr added 2 commits May 19, 2026 22:57
@trivikr
test: update stream pipeline abort expectation
934e839
Expect ECONNRESET when an HTTP response pipeline is closed before the
response finish event is emitted.
@trivikr
test: expect response abort errors
a098f1e
Update HTTP tests that intentionally close the client connection to
expect ECONNRESET from ServerResponse.
@ronag ronag added the semver-major PRs that contain breaking changes and should be released in the next major version. label May 20, 2026
@ronag
ronag requested a review from mcollina May 20, 2026 06:42
@codecov

codecov Bot commented May 20, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.03%. Comparing base (0b5b189) to head (a098f1e).
⚠️ Report is 165 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #63448      +/-   ##
==========================================
- Coverage   90.06%   90.03%   -0.03%     
==========================================
  Files         714      714              
  Lines      225918   225930      +12     
  Branches    42734    42735       +1     
==========================================
- Hits       203464   203422      -42     
- Misses      14232    14281      +49     
- Partials     8222     8227       +5     
Files with missing lines Coverage Δ
lib/_http_outgoing.js 95.81% <100.00%> (+0.01%) ⬆️
lib/_http_server.js 96.63% <100.00%> (+0.02%) ⬆️

... and 34 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@pimterry

pimterry commented May 20, 2026

Copy link
Copy Markdown
Member

We need to link this up to #63249, which actively aims to match the current ServerResponse behaviour that this PR is now changing (neither erroring nor finishing if clients abort). These behaviours need to match.

Do we definitely want to change this though? In the referenced issue (#50656) back in 2023, @ronag said:

The current invariant for Writable streams is that they should always emit either 'error' or 'finish'.

But that's not generally true. There's plenty of counter-examples, most notably calling destroy() on any writables always emits close without error or finish. Similarly, we don't error or finish stdin if a child process cleanly exits:

const { spawn } = require('node:child_process');

const child = spawn('node', ['-e', 'process.exit(0)']);

child.stdin.on('finish', () => console.log('stdin: finish'));
child.stdin.on('error', () => console.log('stdin: error'));
child.stdin.on('close', () => console.log('stdin: close'));

In effect, closed && !errored && !writableFinished is our standard 'clean abort' check. This is sufficiently standard that we check for it explicitly here as part of stream.finished() - automatically turning any such clean abort into a ERR_STREAM_PREMATURE_CLOSE if you're actively waiting for finished as a promise.

In the specific HTTP case this is a very common occurrence (clients abort responses all the time) so this will produce a lot of errors. It's good that it's guarded just for listened events, but still it'll be a very visible behavioural change and it's hard to predict the results of that. Currently, AFAICT most implementations largely happily ignore this scenario unless they're doing something expensive, and they can already detect this manually if they want to.

I'm very open to exploring this more, we could certainly improve stream & HTTP client abort behaviour, but this isn't the existing invariant, and I can see arguments on it both ways so we shouldn't just accept it as given. If we really do want to change it, we should definitely change the HTTP/2 PR above before that's merged too, and then potentially look at changing lots of other Node APIs as well afterwards to try to make this invariant consistent.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@pimterry

pimterry commented May 22, 2026

Copy link
Copy Markdown
Member

Any thoughts on the above @trivikr or @ronag? #63249 is basically ready to merge, but I'm currently holding on that given the open question here about how we want these APIs to work in general.

Personally, I think the current behaviour makes sense (clean abort of a writable = close without finish or error) and is consistent with the rest of our stream APIs. I'd suggest we stick with it, and potentially document better if there are gaps there. Let me know what you think?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@trivikr

trivikr commented May 28, 2026

Copy link
Copy Markdown
Member Author

@ronag Do you have any input on questions shared by @pimterry?

I'd posted this PR on coming across #50656 when searching for issues which mentioned "stream"

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@pimterry

pimterry commented Jun 1, 2026

Copy link
Copy Markdown
Member

Ok, no specific objections here, so I'm going to go ahead with #63249 for now.

Happy to discuss and revisit the close-without-finish/error behaviour later on if there's appetite, but right now I do think that's our standard behaviour, and it's a reasonable solution.

trivikr reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@coderabbitai coderabbitai Bot mentioned this pull request Jun 5, 2026
Fix OpenAI tool format overrides (Fixes #1943) vybestack/llxprt-code#1949
Merged
@trivikr trivikr closed this Jun 6, 2026
@trivikr
trivikr deleted the http-response-emit-error-or-finish branch June 6, 2026 05:41
@coderabbitai coderabbitai Bot mentioned this pull request Jun 11, 2026
chore: request logging + in-memory rate limiting gradionhq/acdc-poc#60
Merged
5 tasks done
@coderabbitai coderabbitai Bot mentioned this pull request Jul 16, 2026
Add customisable alerts overlay for follows/subs/raids Battle-Cattle/BCUK-Bot-4#405
Merged
2 of 3 tasks
This was referenced Jul 28, 2026
feat: add integrated browser oomol-lab/wanta#277
Merged
feat: add opt-in bandwidth monitoring behind BANDWIDTH_MONITOR_ENABLED siteboon/claudecodeui#1094
Open
@coderabbitai coderabbitai Bot mentioned this pull request Aug 6, 2026
feat(webdriver): bound memory per render request genlayerlabs/genvm-manager#23
Closed
@coderabbitai coderabbitai Bot mentioned this pull request Aug 25, 2026
Docs: "bring your own CI" guide — no native CI runner, webhook evaluator contract, sandbox inventory stratum-eng/stratum#217
Merged
8 of 12 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@mcollina mcollina Awaiting requested review from mcollina

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

http Issues and PRs related to the http subsystem. needs-ci PRs that need a full CI run. semver-major PRs that contain breaking changes and should be released in the next major version.

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

HTTP Response doesn't always emit error or finish

Uh oh!

There was an error while loading. Please reload this page.

4 participants

@trivikr @nodejs-github-bot @pimterry @ronag
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.