Skip to content

Memory leakage in SSR while using native node fetch #56586

@vz-tl

Description

@vz-tl

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

ssr

Is this a regression?

Yes

Description

After upgrading our enterprise application to NG17, we also enabled native fetch on SSR using withFetch(). Once after deployment of the upgraded application we encountered permanent memory increase and finally the application restarting due to OOM.

After investigating it became obvious that the heap space size only got exceeded when using native node fetch. Removing withFetch() fixed the problem. Below find a screeshot from Datadog monitoring, which nicely shows what happened over the past weeks.

app_heap_space_usage_graph_4_weeks

In order to exclude a dependency to the node version , we tried with several versions from v20 up to recent v22. The behaviour when using native fetch was reproducible.

Assuming that native node fetch will very likely become standard in future NG versions and the polyfill will become removed, this makes me a bit nervous when seeing our massive problems while using native fetch!

I won't provide a repo at this point, as it requires time preparing it and I am not sure if it will add value, because

  • the issue is so obvious it actually must be known already (even though I'm wondering I didn't find anything related)
  • I'm not fully sure if it is even related to Angular but rather a bug in node / undici implementation (found a lot of not cleaned up undici Timeout references between heap size snapshots)
  • when providing a repro, the memory footprint for such example app is much smaller than with our enterprise app, so it will only be possible to recognize a memory increase by taking multiple memory snapshots while app is requesting data and comparing new instances created but not cleaned up between 2 snapshots.

That's why I first wanna post this issue in hope someone already knows the issue and might have an idea or direction what's causing it or even how to fix it. If still a repro would be required, let me know and I will try to provide one.

Kind regards,
Tobias

Please provide a link to a minimal reproduction of the bug

--

Please provide the exception or error you saw

See above

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

Angular CLI: 17.3.5
Node: 20.11.0
Package Manager: npm 10.2.4
OS: linux x64

Angular: 17.3.5
... animations, cdk, cli, common, compiler, compiler-cli, core
... forms, google-maps, language-service, platform-browser
... platform-browser-dynamic, platform-server, router, ssr
... youtube-player

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1703.5
@angular-devkit/build-angular   17.3.5
@angular-devkit/core            17.3.5
@angular-devkit/schematics      17.3.5
@schematics/angular             17.3.5
ng-packagr                      17.3.0
rxjs                            7.8.1
typescript                      5.4.5
zone.js                         0.14.4

Anything else?

No response

Metadata

Metadata

Assignees

Labels

area: common/httpIssues related to HTTP and HTTP Clientarea: serverIssues related to server-side renderingarea: zonesIssues related to zone.jsmemory leakIssue related to a memory leakstate: has PR

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions