Skip to content

fix(http): cancel oversized fetch response bodies - #70210

Open
SkyZeroZx wants to merge 1 commit into
angular:mainfrom
SkyZeroZx:fix/ssr-fetch
Open

fix(http): cancel oversized fetch response bodies#70210
SkyZeroZx wants to merge 1 commit into
angular:mainfrom
SkyZeroZx:fix/ssr-fetch

Conversation

@SkyZeroZx

Copy link
Copy Markdown
Contributor

Cancel the unread response body before reporting NG02825 when its declared Content-Length exceeds the configured buffer limit. Without cancellation, SSR can finish while the underlying connection remains open.

What is the current behavior?

FetchBackend rejects a response when its declared Content-Length exceeds the configured buffer limit. This happens before Angular creates a body reader, and the response body is not cancelled on this rejection path.

In a local Angular 22.1.2 SSR application, five declared-length responses were rejected but all five connections remained open. The equivalent streamed-overrun case rejected all five responses and cancelled all five streams.

The smallest response used in the reproduction declared Content-Length: 1048577, sent no body bytes, and kept the socket open. Eight SSR requests left eight outbound connections open after two seconds.

Without cancellation, repeated requests can retain outbound connections after their Angular requests have already failed. The observed effect was socket and file-descriptor pressure rather than allocation of the declared response body.

A bounded availability test used one CPU, 256 MiB of memory, a healthy upstream with 250 ms latency, and approximately 192 open responses:

FD limit and tested load Clean worker Worker with open responses
256 FDs, 20 renders 20/20 OK 11 OK, 9 network errors
512 FDs, 300 renders 300/300 OK 260 OK, 40 network errors

Cancel the unread response body before reporting NG02825 when its declared Content-Length exceeds the configured buffer limit. Without cancellation, SSR can finish while the underlying connection remains open.

Add regression coverage for the declared-length rejection path.
@pullapprove
pullapprove Bot requested a review from JeanMeche August 14, 2026 18:03
@angular-robot angular-robot Bot added the area: common/http Issues related to HTTP and HTTP Client label Aug 14, 2026
@ngbot ngbot Bot added this to the Backlog milestone Aug 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: common/http Issues related to HTTP and HTTP Client

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant