Skip to content

fix(@angular/ssr): destroy the platform of an aborted request once it… - #34755

Open
SkyZeroZx wants to merge 1 commit into
angular:mainfrom
SkyZeroZx:fix/ssr-abort-in-flight-render
Open

SkyZeroZx wants to merge 1 commit into
angular:mainfrom
SkyZeroZx:fix/ssr-abort-in-flight-render

Conversation

@SkyZeroZx

Copy link
Copy Markdown
Contributor

… is stable

Aborting a request destroyed the platform while an app initializer or an HttpClient request was still pending, which could end the server process. The platform is now destroyed once the application is stable, or after 10 seconds.

Fixes #34754

… is stable

Aborting a request destroyed the platform while an app initializer or an
`HttpClient` request was still pending, which could end the server
process. The platform is now destroyed once the application is stable,
or after 10 seconds.

Fixes angular#34754

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request improves the handling of aborted renders in Angular SSR by delaying platform destruction until the application becomes stable or a 10-second timeout elapses, preventing pending work from failing abruptly. The review feedback recommends replacing AbortSignal.timeout with standard setTimeout and clearTimeout to prevent the Node.js event loop from hanging in serverless environments, and provides corresponding adjustments for the test suite.

Comment on lines +113 to +114
let abortTimeoutSignal: AbortSignal | undefined;
let isStable = false;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

Instead of using AbortSignal.timeout, which creates a timer that cannot be cleared manually and can keep the Node.js event loop active (potentially causing serverless functions to hang or delay termination), we can use a standard setTimeout and clearTimeout approach. This is simpler, more compatible, and avoids event loop retention issues.

Suggested change
let abortTimeoutSignal: AbortSignal | undefined;
let isStable = false;
let abortTimeoutId: ReturnType<typeof setTimeout> | undefined;
let isStable = false;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

AbortSignal.timeout() doesn't keep the event loop alive, in Node its timer is unref'd. I tested it with the built server: aborting a request whose render never becomes stable and then closing the server, the process exits right away (0.00 s), while with a setTimeout it waits for the timer (9.83 s).

It's also what the route extraction and render workers already use for their 30 s deadlines, and the listener is removed when the platform is destroyed, so the timer firing later does nothing. Keeping it as is.

Comment thread packages/angular/ssr/src/utils/ng.ts Resolved
Comment thread packages/angular/ssr/test/app_spec.ts Resolved
Comment thread packages/angular/ssr/test/app_spec.ts Resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Angular SSR can crash AngularAppEngine servers with a single aborted request (22.2.6 regression)

1 participant