Repository navigation
Conversation
… 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
There was a problem hiding this comment.
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.
| let abortTimeoutSignal: AbortSignal | undefined; | ||
| let isStable = false; |
There was a problem hiding this comment.
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.
| let abortTimeoutSignal: AbortSignal | undefined; | |
| let isStable = false; | |
| let abortTimeoutId: ReturnType<typeof setTimeout> | undefined; | |
| let isStable = false; |
There was a problem hiding this comment.
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.
… is stable
Aborting a request destroyed the platform while an app initializer or an
HttpClientrequest 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