Skip to content

Don't report a client-aborted RSC stream as a render error - #96715

Merged
gaojude merged 2 commits into
vercel:canaryfrom
lazerg:fix/issue-96704-rsc-client-abort
Aug 26, 2026
Merged

gaojude merged 2 commits into
vercel:canaryfrom
lazerg:fix/issue-96704-rsc-client-abort

Conversation

@lazerg

@lazerg lazerg commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

When a client disconnects mid-stream, pipeNodeReadableToNodeResponse destroys the readable React is piping into. React sees its destination close before the render ended and aborts with a generic Error("The destination stream closed early."), which onError has no way to distinguish from a real render error, so it ends up in onRequestError as a server render error.

The Web streams path doesn't have this problem: cancelling the readable passes the ResponseAborted reason straight through to React. This does the same for the Node path by aborting the pipeable with that reason as soon as the passthrough is destroyed early, before React's own close handler runs. Genuine render errors still go through untouched.

Fixes #96704

@lazerg

lazerg commented Aug 8, 2026

Copy link
Copy Markdown
Contributor Author

Hey @sampoder, @eps1lon, @mischnic please look at this when you have time 🙏

This is on draft, but it is actually done, I just could not move it to open since I already have three open PRs on this repo.

gaojude pushed a commit that referenced this pull request Aug 25, 2026
…zip (#97698)

## Summary

On Next 16.3+, App Router HTML and RSC responses are piped with
`pipeNodeReadableToNodeResponse`. Under gzip backpressure it called
`res.once('drain')` on every write that returned `false`, which leaks
one listener per backpressured write onto the zlib stream:

```
MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 drain listeners added to [Gzip]. MaxListeners is 10.
```

The `compression` middleware overrides only `res.on`, forwarding it to
the zlib stream once that stream exists (or buffering it until then). It
leaves `removeListener` pointing at the response, so a `once` listener
is added to the stream but never removed from it. `off` cannot reach it
either.

`createWriterFromResponse`, directly above in the same file, already
uses a single `res.on('drain')` for the response lifetime. This makes
the Node-readable path match: pause on `write() === false`, resume from
one listener, `off` on `close`.

Resuming on that event is correct for both cases. With compression
active the wrapped `res.write` writes into the zlib stream, so `false`
means the zlib stream's buffer is full and its `drain` is the right
signal — the middleware separately wires the socket's `drain` to
`stream.resume()`. With compression inactive the listener stays on the
response, where `off` does remove it.

The pause is latched so a `drain` only resumes a readable that this
function paused, and a `drain` arriving after teardown is ignored.

### Scope

- Distinct from #96173 / `releaseCompressionStream`, which destroys the
zlib stream on **abort**. This warning fires on a **live** stream that
is still flowing: slow clients, large streamed HTML/RSC.
- Deliberately leaves the bare `readable.destroy()` in the `close`
handler alone. That is the separate abort-reason bug in #96704, with
fixes already open in #96715 and #96717.
- Not fixable by bumping the vendored `compression`: as #96173
established, upstream `compression@1.8.1` still has no premature-close
handling, and it is a prebuilt bundle here. `setMaxListeners` or
`compress: false` would only hide this.
- Mentioned as a `compress: false` workaround in #95130.

## Verification

`packages/next/src/server/pipe-readable.test.ts` drives real
backpressure (48 × 64 KiB through a throttled reader) and asserts
exactly one `drain` registration on the zlib stream, no
`MaxListenersExceededWarning`, and a complete, byte-correct payload
after `gunzip`. The payload assertion is what catches a latch that
stalls the stream.

Confirmed it fails without the fix. Measured against the real compiled
function on Next 16.3, patching only the drain handling:

| | before | after |
| --- | --- | --- |
| `drain` registrations on `[Gzip]` | 48 (one per backpressured write) |
**1** |
| `MaxListenersExceededWarning` | 1 | **0** |
| decompressed payload | complete | complete |

At 120 × 64 KiB the before-count scales with writes (120 registrations);
the after-count stays at 1. Separately reproduced end to end on a Next
16.3 standalone production build with `compress: true`: slow-consuming a
large gzipped page emitted the warning, and after this change it did
not, with `Content-Encoding: gzip` still set and valid gzip on the wire.

I could not run `pnpm test` in this checkout, so please treat CI as the
source of truth for harness integration. The assertions themselves were
validated against the real function as described above.

---------

Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Jude Gao <jude.gao@vercel.com>
Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
@gaojude
gaojude force-pushed the fix/issue-96704-rsc-client-abort branch from e3a23e0 to cd10fdf Compare August 25, 2026 13:51
@gaojude

gaojude commented Aug 25, 2026

Copy link
Copy Markdown

Maintainer note: force-pushed a rebase of your commit onto current canary (patch-id identical, authorship preserved, commit signed) so CI runs against tip. Verified locally: the new client-abort test passes in all four modes (dev/start x turbopack/webpack), the existing on-request-error basic suite still passes, and a live repro of #96704 goes from misreporting to clean with this build. @lazerg could you mark this ready for review? GitHub won't let me convert your draft. Review to follow.

@lazerg
lazerg marked this pull request as ready for review August 25, 2026 13:58
@lazerg

lazerg commented Aug 25, 2026

Copy link
Copy Markdown
Contributor Author

Marked ready for review. Thanks for the rebase and verification.

The cache-components CI matrix force-enables cacheComponents for every
e2e test, which rejects the `dynamic = 'force-dynamic'` segment config
(the /hang and /error fixtures 500'd in dev and failed the prod build).
Use `await connection()` inside a Suspense boundary instead, which makes
the pages dynamic in every mode.
@github-actions

github-actions Bot commented Aug 25, 2026 •

Copy link
Copy Markdown
Contributor

Tests Passed

Commit: 2787b16

@github-actions

Copy link
Copy Markdown
Contributor

Stats from current PR

🔴 1 regression

Metric Canary PR Change
node_modules Size 553 MB 554 MB 🔴 +1.03 MB (+0%)
📊 All Metrics
📖 Metrics Glossary

Dev Server Metrics:

  • Listen = TCP port starts accepting connections
  • First Request = HTTP server returns successful response
  • Cold = Fresh build (no cache)
  • Warm = With cached build artifacts

Build Metrics:

  • Fresh = Clean build (no .next directory)
  • Cached = With existing .next directory

Change Thresholds:

  • Time: Changes < 50ms AND < 10%, OR < 2% are insignificant
  • Size: Changes < 1KB AND < 1% are insignificant
  • All other changes are flagged to catch regressions

⚡ Dev Server

Metric Canary PR Change
Cold (Listen) 812ms 811ms ✓
Cold (Ready in log) 791ms 788ms ✓
Cold (First Request) 1.248s 1.246s ✓
Warm (Listen) 811ms 811ms ✓
Warm (Ready in log) 780ms 795ms ✓
Warm (First Request) 1.235s 1.248s ✓
📦 Dev Server (Webpack) (Legacy)

📦 Dev Server (Webpack)

Metric Canary PR Change
Cold (Listen) 862ms 816ms ✓
Cold (Ready in log) 821ms 822ms ✓
Cold (First Request) 3.499s 3.477s ✓
Warm (Listen) 814ms 863ms ✓
Warm (Ready in log) 818ms 826ms ✓
Warm (First Request) 3.518s 3.545s ✓

⚡ Production Builds

Metric Canary PR Change
Fresh Build 5.709s 5.571s ✓
Cached Build 2.877s 2.870s ✓
📦 Production Builds (Webpack) (Legacy)

📦 Production Builds (Webpack)

Metric Canary PR Change
Fresh Build 25.529s 25.729s ✓
Cached Build 25.769s 25.816s ✓
node_modules Size 553 MB 554 MB 🔴 +1.03 MB (+0%)
📦 Bundle Sizes

Bundle Sizes

⚡ Turbopack

Client

Main Bundles
Canary PR Change
017_4moyv5m34.js gzip 117 B 117 B ✓
05jocc85-b73_.js gzip 341 B N/A -
096twxhe86hwd.js gzip 7.53 kB N/A -
0cz1d0mv5g_q7.js gzip 39.4 kB 39.4 kB ✓
0e5lgz-xcf6ln.js gzip 273 B 273 B ✓
0enhddgqs2dl-.js gzip 265 B 265 B ✓
0h34mejwa_7pd.js gzip 354 B 354 B ✓
0mg5-nyl2xcjy.js gzip 65.5 kB N/A -
0w853zxni3ro0.js gzip 1.36 kB N/A -
13lq2aw3_0bgw.js gzip 3.52 kB N/A -
17wjm_wc16a_w.js gzip 71.5 kB N/A -
1drifx6-oqf3q.js gzip 5.7 kB N/A -
1elt1qium-r2m.css gzip 115 B 115 B ✓
1m5vdnlf0deiv.js gzip 411 B 411 B ✓
1nigpy_mr0xvj.js gzip 339 B N/A -
1p0l8mn2wz5f2.js gzip 1.97 kB N/A -
1sqoyy39jpgkq.js gzip 121 B 121 B ✓
1tf1phijqlx9j.js gzip 220 B 220 B ✓
2-54v5vj7orwp.js gzip 46.8 kB N/A -
26upjmii0ixt5.js gzip 153 B N/A -
2b05_424u1zq-.js gzip 120 B N/A -
2ca40xittx95r.js gzip 8.75 kB N/A -
2kci0vnt-49o-.js gzip 113 B 113 B ✓
2rtriq9lc6zj-.js gzip 116 B N/A -
2sxgl_rcrrn_p.js gzip 399 B N/A -
2vt62i17bhbdu.js gzip 2.35 kB N/A -
342di-crrg9kq.js gzip 119 B N/A -
36hfc2_979aw2.js gzip 119 B N/A -
38wfp6jjrrdfm.js gzip 131 B 131 B ✓
3dl1ilk37-30g.js gzip 117 B N/A -
3h0us7yy7bd_o.js gzip 13.1 kB N/A -
3kvxagoobts7h.js gzip 117 B N/A -
3p99hd9vwe6ae.js gzip 13 kB N/A -
3r0475panhk6m.js gzip 123 B N/A -
3s0i-weykgzrt.js gzip 125 B N/A -
3vjosdbddykpw.js gzip 5.88 kB N/A -
3wijk2ywqgsv9.js gzip 2.52 kB N/A -
41u5s3oe2-erp.js gzip 2.29 kB N/A -
turbopack-0d..9ejy.js gzip 3.74 kB 3.74 kB ✓
02zc7sqlpqxn3.js gzip N/A 119 B -
06pzxqp5qiozm.js gzip N/A 5.7 kB -
0dug3edczk4gl.js gzip N/A 71.5 kB -
0e28eh3gbwmp0.js gzip N/A 3.51 kB -
0e53csrecof4e.js gzip N/A 65.5 kB -
0jwho9fkrb_t3.js gzip N/A 2.29 kB -
0longconn5mlm.js gzip N/A 123 B -
0p4l3ozbez2cz.js gzip N/A 2.35 kB -
0sbh_15ejop4o.js gzip N/A 13 kB -
0skdm-9rpid8g.js gzip N/A 117 B -
0wv-h56sz83wn.js gzip N/A 120 B -
137xup2t69ovc.js gzip N/A 1.97 kB -
1ezuqvubf86h1.js gzip N/A 5.88 kB -
1fk10s3m1oecx.js gzip N/A 400 B -
1hut5u-lz2yif.js gzip N/A 117 B -
20qhkyyj2_tla.js gzip N/A 116 B -
2imyufe18bsb7.js gzip N/A 1.36 kB -
2p4n3-8-xixh_.js gzip N/A 341 B -
2vqdfieehz5do.js gzip N/A 8.75 kB -
2x99jdcpr5n8x.js gzip N/A 7.53 kB -
2xn85ykzw2v1e.js gzip N/A 13.1 kB -
34knadd6wu9qg.js gzip N/A 119 B -
39jq2b6t6z6up.js gzip N/A 339 B -
3a9a9tvkag_-j.js gzip N/A 2.52 kB -
3b660b4ak0547.js gzip N/A 153 B -
3d61tgick8g6b.js gzip N/A 46.8 kB -
3t121tj-h0kbm.js gzip N/A 125 B -
Total 299 kB 299 kB ⚠️ +3 B

Server

Middleware
Canary PR Change
middleware-b..fest.js gzip 1.02 kB 1.03 kB ✓
Total 1.02 kB 1.03 kB ⚠️ +1 B
Build Details
Build Manifests
Canary PR Change
_buildManifest.js gzip 846 B 848 B ✓
Total 846 B 848 B ⚠️ +2 B
Build Cache
Canary PR Change
00000001.sst gzip 12.4 MB 13.8 MB 🔴 +1.4 MB (+11%)
00000002.sst gzip 13.1 MB 13.6 MB 🔴 +496 kB (+4%)
00000003.sst gzip 14.2 MB 14.3 MB 🔴 +163 kB (+1%)
00000004.sst gzip 15.1 MB 13.1 MB 🟢 2.03 MB (-13%)
00000005.sst gzip 10.1 MB 2.75 MB 🟢 7.33 MB (-73%)
00000006.sst gzip 2.75 MB 10.1 MB 🔴 +7.33 MB (+266%)
00000007.sst gzip 59 B 59 B ✓
00000008.meta gzip 89 B 297 kB 🔴 +297 kB (+333607%)
00000009.meta gzip 297 kB 89 B 🟢 297 kB (-100%)
00000010.meta gzip 297 kB 297 kB ✓
00000011.meta gzip 297 kB 297 kB ✓
00000012.sst gzip 52.7 kB 51.7 kB 🟢 991 B (-2%)
00000013.sst gzip 1.77 MB 1.74 MB 🟢 29.8 kB (-2%)
00000014.sst gzip 59 B 59 B ✓
00000015.meta gzip 116 B 116 B ✓
00000016.meta gzip 326 kB 327 kB ✓
00000017.meta gzip 404 kB 402 kB ✓
00000018.sst gzip 53.4 kB 52.7 kB 🟢 650 B (-1%)
00000019.sst gzip 1.36 MB 1.36 MB ✓
00000020.sst gzip 59 B 59 B ✓
00000021.meta gzip 116 B 116 B ✓
00000022.meta gzip 326 kB 327 kB ✓
00000023.meta gzip 372 kB 372 kB ✓
00000024.sst gzip 53.4 kB 52.8 kB 🟢 601 B (-1%)
00000025.sst gzip 1.36 MB 1.36 MB ✓
00000026.sst gzip 59 B 59 B ✓
00000027.meta gzip 116 B 116 B ✓
00000028.meta gzip 326 kB 327 kB ✓
00000029.meta gzip 372 kB 372 kB ✓
00000030.sst gzip 52.6 kB 52 kB 🟢 668 B (-1%)
00000031.sst gzip 1.36 MB 1.36 MB ✓
00000032.sst gzip 59 B 59 B ✓
00000033.meta gzip 116 B 116 B ✓
00000034.meta gzip 326 kB 327 kB ✓
00000035.meta gzip 372 kB 372 kB ✓
00000036.sst gzip 53.3 kB 52.7 kB 🟢 586 B (-1%)
00000037.sst gzip 1.36 MB 1.36 MB ✓
00000038.sst gzip 59 B 59 B ✓
00000039.meta gzip 116 B 116 B ✓
00000040.meta gzip 326 kB 327 kB ✓
00000041.meta gzip 372 kB 372 kB ✓
CURRENT gzip 94 B 94 B ✓
LOG gzip 690 B 672 B 🟢 18 B (-3%)
Total 79.5 MB 79.5 MB ✅ -5.05 kB

📦 Webpack

Client

Main Bundles
Canary PR Change
3322-HASH.js gzip 65.7 kB N/A -
4191.HASH.js gzip 169 B N/A -
9784-HASH.js gzip 5.6 kB N/A -
b1ad9f4c-HASH.js gzip 63.5 kB N/A -
framework-HASH.js gzip 59.7 kB 59.7 kB ✓
main-app-HASH.js gzip 253 B 252 B ✓
main-HASH.js gzip 39.8 kB 39.7 kB ✓
webpack-HASH.js gzip 1.68 kB 1.68 kB ✓
3577.HASH.js gzip N/A 168 B -
578-HASH.js gzip N/A 65.8 kB -
8590-HASH.js gzip N/A 5.57 kB -
a8984546-HASH.js gzip N/A 63.5 kB -
Total 236 kB 236 kB ⚠️ +105 B
Polyfills
Canary PR Change
polyfills-HASH.js gzip 39.4 kB 39.4 kB ✓
Total 39.4 kB 39.4 kB ✓
Pages
Canary PR Change
_app-HASH.js gzip 194 B 193 B ✓
_error-HASH.js gzip 181 B 182 B ✓
css-HASH.js gzip 334 B 331 B ✓
dynamic-HASH.js gzip 1.81 kB 1.81 kB ✓
edge-ssr-HASH.js gzip 255 B 253 B ✓
head-HASH.js gzip 349 B 351 B ✓
hooks-HASH.js gzip 382 B 384 B ✓
image-HASH.js gzip 5.05 kB 5.05 kB ✓
index-HASH.js gzip 260 B 259 B ✓
link-HASH.js gzip 2.48 kB 2.48 kB ✓
routerDirect..HASH.js gzip 317 B 318 B ✓
script-HASH.js gzip 384 B 386 B ✓
withRouter-HASH.js gzip 316 B 315 B ✓
1afbb74e6ecf..834.css gzip 106 B 106 B ✓
Total 12.4 kB 12.4 kB ✅ -6 B

Server

Edge SSR
Canary PR Change
edge-ssr.js gzip 128 kB 128 kB ✓
page.js gzip 293 kB 293 kB ✓
Total 421 kB 421 kB ✅ -404 B
Middleware
Canary PR Change
middleware-b..fest.js gzip 601 B 602 B ✓
middleware-r..fest.js gzip 156 B 156 B ✓
middleware.js gzip 45.5 kB 45.3 kB ✓
edge-runtime..pack.js gzip 842 B 842 B ✓
Total 47.1 kB 46.9 kB ✅ -244 B
Build Details
Build Manifests
Canary PR Change
_buildManifest.js gzip 699 B 699 B ✓
Total 699 B 699 B ✓
Build Cache
Canary PR Change
0.pack gzip 4.8 MB 4.79 MB 🟢 5.29 kB (0%)
index.pack gzip 124 kB 123 kB ✓
index.pack.old gzip 124 kB 124 kB ✓
Total 5.05 MB 5.04 MB ✅ -5.92 kB

🔄 Shared (bundler-independent)

Runtimes
Canary PR Change
app-page-exp...dev.js gzip 375 kB 377 kB 🔴 +2.38 kB (+1%)
app-page-exp..prod.js gzip 206 kB 207 kB ✓
app-page-tur...dev.js gzip 374 kB 377 kB 🔴 +2.38 kB (+1%)
app-page-tur..prod.js gzip 206 kB 207 kB ✓
app-page-tur...dev.js gzip 370 kB 373 kB 🔴 +2.46 kB (+1%)
app-page-tur..prod.js gzip 204 kB 205 kB ✓
app-page.run...dev.js gzip 371 kB 373 kB 🔴 +2.46 kB (+1%)
app-page.run..prod.js gzip 204 kB 205 kB ✓
app-route-ex...dev.js gzip 82.6 kB 82.6 kB ✓
app-route-ex..prod.js gzip 55.7 kB 55.7 kB ✓
app-route-tu...dev.js gzip 82.6 kB 82.6 kB ✓
app-route-tu..prod.js gzip 55.7 kB 55.7 kB ✓
app-route-tu...dev.js gzip 82.2 kB 82.2 kB ✓
app-route-tu..prod.js gzip 55.4 kB 55.4 kB ✓
app-route.ru...dev.js gzip 82.2 kB 82.2 kB ✓
app-route.ru..prod.js gzip 55.4 kB 55.4 kB ✓
dev-validati...dev.js gzip 134 kB 139 kB 🔴 +4.71 kB (+4%)
dev-validati...dev.js gzip 134 kB 139 kB 🔴 +4.72 kB (+4%)
dev-validati...dev.js gzip 132 kB 137 kB 🔴 +4.77 kB (+4%)
dev-validati...dev.js gzip 132 kB 137 kB 🔴 +4.76 kB (+4%)
dist_client_...dev.js gzip 324 B 324 B ✓
dist_client_...dev.js gzip 326 B 326 B ✓
dist_client_...dev.js gzip 318 B 318 B ✓
dist_client_...dev.js gzip 317 B 317 B ✓
pages-api-tu...dev.js gzip 46.3 kB 46.3 kB ✓
pages-api-tu..prod.js gzip 34.3 kB 34.3 kB ✓
pages-api.ru...dev.js gzip 46.2 kB 46.2 kB ✓
pages-api.ru..prod.js gzip 34.3 kB 34.3 kB ✓
pages-turbo....dev.js gzip 54.7 kB 54.7 kB ✓
pages-turbo...prod.js gzip 39.7 kB 39.7 kB ✓
pages.runtim...dev.js gzip 54.7 kB 54.7 kB ✓
pages.runtim..prod.js gzip 39.6 kB 39.6 kB ✓
server.runti..prod.js gzip 65.9 kB 65.9 kB ✓
use-cache-pr...dev.js gzip 73.3 kB 73.3 kB ✓
use-cache-pr...dev.js gzip 73.3 kB 73.3 kB ✓
use-cache-pr...dev.js gzip 71.5 kB 71.5 kB ✓
use-cache-pr...dev.js gzip 71.5 kB 71.5 kB ✓
Total 4.1 MB 4.13 MB ⚠️ +32 kB
📝 Changed Files (12 files)

Files with changes:

  • app-page-exp..ntime.dev.js
  • app-page-exp..time.prod.js
  • app-page-tur..ntime.dev.js
  • app-page-tur..time.prod.js
  • app-page-tur..ntime.dev.js
  • app-page-tur..time.prod.js
  • app-page.runtime.dev.js
  • app-page.runtime.prod.js
  • dev-validati..ntime.dev.js
  • dev-validati..ntime.dev.js
  • dev-validati..ntime.dev.js
  • dev-validati..ntime.dev.js
View diffs
app-page-exp..ntime.dev.js
failed to diff
app-page-exp..time.prod.js
failed to diff
app-page-tur..ntime.dev.js
failed to diff
app-page-tur..time.prod.js
failed to diff
app-page-tur..ntime.dev.js
failed to diff
app-page-tur..time.prod.js
failed to diff
app-page.runtime.dev.js
failed to diff
app-page.runtime.prod.js
failed to diff
dev-validati..ntime.dev.js
failed to diff
dev-validati..ntime.dev.js
failed to diff
dev-validati..ntime.dev.js
failed to diff
dev-validati..ntime.dev.js
failed to diff
📎 Tarball URL
https://vercel-packages.vercel.app/next/commits/2787b1692fcc3905180a3b226dce88ff90e0f94b/next

Commit: 2787b16

@gaojude gaojude left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Reproduced #96704 on stock 16.3.x and verified this fix end to end: typed abort lands before React's generic close handler (confirmed against the compiled flight server), new test passes in dev/start x turbopack/webpack and under the cache-components matrix, and a live repro goes from misreport to clean with render cancellation preserved.

@gaojude
gaojude merged commit 0c7f81e into vercel:canary Aug 26, 2026
219 of 222 checks passed
kouloumos added a commit to schemalabz/opencouncil that referenced this pull request Sep 6, 2026
Next 16.3.0 reports a client that disconnects mid-stream as a server
render error. When the browser drops an in-flight RSC request,
pipeNodeReadableToNodeResponse destroys the PassThrough that React
streams the flight payload into. React sees its destination close
before the render ends. It cancels the render with a plain
Error('The destination stream closed early.').

Next drops client aborts in createReactServerErrorHandler, but its
isAbortError check matches only the names AbortError and
ResponseAborted. The generic error passes that filter, reaches
onRequestError and raises a Discord alert that nobody can act on.
Production started to receive these alerts after the bump to Next
16.3.4 in 44d05dc.

Skip the two messages React uses when it cancels a render because the
destination went away. Application code cannot produce either message.
Remove the guard with the upgrade to Next 16.4, which carries the
upstream fix (vercel/next.js#96715).
@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Sep 10, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Client-aborted RSC stream is reported to onRequestError as "The destination stream closed early."

2 participants