Repository navigation
fix(@angular/ssr): harden platform destruction and abort/response cleanup guards - #34781
Open
alan-agius4 wants to merge 3 commits into
Open
alan-agius4 wants to merge 3 commits into
alan-agius4 wants to merge 3 commits into
Conversation
There was a problem hiding this comment.
Code Review
This pull request improves SSR request handling and lifecycle management by ensuring that SSR requests are aborted on client disconnect or timeout, response bodies are cancelled when the destination is closed, and platform/injector destruction is handled gracefully. The review feedback highlights two important robustness improvements: providing a fallback for AbortSignal.any to support Node.js versions prior to v20.3.0, and using optional chaining when accessing destination.req.url to prevent potential TypeErrors.
…uards - Guard `platformRef.destroy()` in `getRoutesFromAngularRouterConfig` against already-destroyed platforms and catch/log destroy-hook errors so route extraction neither fails nor masks earlier errors. - Check `applicationRef.injector.destroyed` and `destroyPromise` consistently across `renderAngular` bootstrap, stability, and `content()` guards. - Cancel unlocked `source.body` streams when `writeResponseToNodeResponse` returns early for an already-closed Node response.
Combine the client-disconnect `AbortSignal` from `createWebRequestFromNodeRequest` with `AbortSignal.timeout(30_000)` using `AbortSignal.any` instead of replacing the client signal in `createAngularSsrInternalMiddleware`.
alan-agius4
force-pushed
the
fix/ssr-abort-destroy-followups
branch
from
November 24, 2026 08:23
413cdfa to
930d82e
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
PR Checklist
PR Type
What is the current behavior?
Follow-up hardening after #34768 (related to #34754 / #34777):
getRoutesFromAngularRouterConfig()callsplatformRef.destroy()directly infinallywithout checking!platformRef.destroyedor catching destroy-hook errors, which can throwNG0404, fail route extraction, or mask errors thrown insidetry.renderAngular()checksplatformRef.destroyedandapplicationRef.destroyed, but does not checkapplicationRef.injector.destroyed(ordestroyPromisebeforecontent()), which can still throwNG0205if the environment injector is marked destroyed beforeApplicationRef.ngOnDestroy()completes.writeResponseToNodeResponse()returns early when the Node destination is already closed/destroyed without cancellingsource.body.createAngularSsrInternalMiddleware()wrapscreateWebRequestFromNodeRequest(req)with{ signal: AbortSignal.timeout(30_000) }, replacing the client-disconnectAbortSignalinstead of combining both signals.What is the new behavior?
platformRef.destroy()ingetRoutesFromAngularRouterConfig()withif (!platformRef.destroyed)and catch/log destroy-hook errors viaconsole.error.destroyPromise,platformRef.destroyed,applicationRef.destroyed,applicationRef.injector.destroyed, andsignal?.abortedconsistently acrossrenderAngular()andcontent()(and replace silent early-return guards inng_spec.tswithnode:assert).source.bodystreams (with error logging) whenwriteResponseToNodeResponse()returns early on an already-closed Node response.nodeWebReq.signalandAbortSignal.timeout(30_000)usingAbortSignal.any()increateAngularSsrInternalMiddleware().Does this PR introduce a breaking change?