Skip to content

SSG Prerendering gives timeout when rendering big numb of urls or api takes time to response #29135

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
uttamughareja opened this issue Dec 13, 2024 · 6 comments

Comments

@uttamughareja
Copy link

Which @angular/* package(s) are the source of the bug?

core

Is this a regression?

No

Description

I tried to build my app with following setting, I have ~20k urls to build. and because all requests are sent concurrently from the build process, the api is taking time to process all these concurrent requests.
{
...
"prerender":{
"routesFile": "prerender-urls.txt",
"discoverRoutes": false
},
"ssr": false
...
}

because of this delay, the page is taking more time to response than Agular build process waits and it fails with timeout error.

I did my research and opened a stackoverflow issue after I couldn't find any proper solution to this. I see other people facing the same problem. so opening this issue.

Please provide a link to a minimal reproduction of the bug

create a new app with 1 component, enable prerender with few diff parameter urls that needs backend api calls, api should simulate a delay in response about 5 min or more to make it happen fast, build angular app and wait until the build throws a timeout error.

Please provide the exception or error you saw

Prerendered 3 static routes.
Application bundle generation failed. [133.998 seconds]

X [ERROR] An error occurred while prerendering route '/jumbo'.

AbortError: Request for: http://ng-localhost/pens was aborted.
TimeoutError: The operation was aborted due to timeout
    at e.signal.addEventListener.once (file:///D:/Frontend/.angular/prerender-root/bb5c5a0f-dd0d-4247-9895-f97bd3bef5b1/main.server.mjs:74:4998)
    at [nodejs.internal.kHybridDispatch] (node:internal/event_target:820:20)
    at EventTarget.dispatchEvent (node:internal/event_target:755:26)
    at abortSignal (node:internal/abort_controller:370:10)
    at AbortController.abort (node:internal/abort_controller:392:5)
    at EventTarget.abort (node:internal/deps/undici/undici:5038:21)
    at [nodejs.internal.kHybridDispatch] (node:internal/event_target:820:20)
    at EventTarget.dispatchEvent (node:internal/event_target:755:26)
    at abortSignal (node:internal/abort_controller:370:10)
    at Timeout._onTimeout (node:internal/abort_controller:127:7)


X [ERROR] An error occurred while prerendering route '/'.

Error: Terminating worker thread
    at ThreadPool.destroy (D:\Frontend\node_modules\piscina\dist\index.js:428:27)
    at WorkerPool.destroy (D:\Frontend\node_modules\piscina\dist\index.js:631:65)
    at D:\Frontend\node_modules\@angular\build\src\utils\server-rendering\prerender.js:147:35
    at async Promise.all (index 4)
    at async renderPages (D:\Frontend\node_modules\@angular\build\src\utils\server-rendering\prerender.js:151:9)
    at async prerenderPages (D:\Frontend\node_modules\@angular\build\src\utils\server-rendering\prerender.js:93:49)
    at async executePostBundleSteps (D:\Frontend\node_modules\@angular\build\src\builders\application\execute-post-bundle.js:68:73)
    at async executeBuild (D:\Frontend\node_modules\@angular\build\src\builders\application\execute-build.js:170:24)
    at async watch (D:\Frontend\node_modules\@angular\build\src\builders\application\index.js:70:24)
    at async Task.task [as taskFn] (D:\Frontend\node_modules\@angular\build\src\tools\esbuild\utils.js:140:26)

Please provide the environment you discovered this bug in (run ng version)

Angular CLI: 19.0.2
Node: 20.15.1
Package Manager: npm 10.7.0
OS: win32 x64

Angular: 19.0.1
... animations, common, compiler, compiler-cli, core, forms
... platform-browser, platform-browser-dynamic, platform-server
... router

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1900.2
@angular-devkit/build-angular   19.0.2
@angular-devkit/core            19.0.2
@angular-devkit/schematics      19.0.2
@angular/cli                    19.0.2
@angular/ssr                    19.0.2
@schematics/angular             19.0.2
rxjs                            7.8.1
typescript                      5.6.3

Anything else?

it would be helpful if there is a way either in angular or node rendering engine to set a value for wait period before throwing a timeout error.

I believe this is one of the most common scenarios that many people are and will face it while using SSG with large amount of pages and slow apis.

thanks

@bougwal
Copy link
Contributor

bougwal commented Dec 13, 2024

@uttamughareja you can have a look at #29005 in the CLI project. A similar discussion (feature request) to make the time_out configurable has been discussed. I hope that helps to shed some light on what you are facing and give you some directions.

@alan-agius4 alan-agius4 transferred this issue from angular/angular Dec 14, 2024
@alan-agius4
Copy link
Collaborator

alan-agius4 commented Dec 16, 2024

I tried to build my app with following setting, I have ~20k urls to build. and because all requests are sent concurrently from the build process, the api is taking time to process all these concurrent requests.

This is not entirely accurate, as only up to four routes are generated in parallel. While we could implement an option to configure the timeout, it raises the question about how the APIs will perform under real traffic conditions in production environments.

@imaksp
Copy link

imaksp commented Dec 16, 2024

Hi, based on above response, you should verify if your server is getting all requests in parallel or only four by adding request log in server. 30 sec seems like a reasonable timeout.

@alan-agius4
Copy link
Collaborator

alan-agius4 commented Dec 16, 2024

If you need to reduce the number of pages being rendered simultaneously, you can configure the NG_BUILD_MAX_WORKERS environment variable. Which defaults to a max of 4.

@alan-agius4
Copy link
Collaborator

Closing, as rendering a single route in approximately 30 seconds seems reasonable. However, it is recommended to improve the API performance, as limiting to only 4 parallel requests can cause a significant bottleneck, even in a production environment. As a workaround, you can use the use the environment variable mentioned above to reduce the number of routes rendered in parallel, which has an upper limit of 4.

@alan-agius4 alan-agius4 closed this as not planned Won't fix, can't repro, duplicate, stale Dec 17, 2024
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Jan 17, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants