Skip to content

Conversation

@JeanMeche
Copy link
Member

The bootstrap() phase might fail e.g. due to an rejected promise in some APP_INIIALIZER. If PlatformRef is not destroyed, then the main app's injector is not destroyed and therefore ngOnDestroy hooks of singleton services is not called on the end (failure) of SSR.

This could lead to possible memory leaks in custom SSR apps, if their singleton services' ngOnDestroy hooks contained an important teardown logic (e.g. unsubscribing from RxJS observable).

Note: I needed to fix by the way another thing too: now we destroy moduleRef when platformInjector is destroyed - by setting a PLATFORM_DESTROY_LISTENER

Patch port of #58112

@JeanMeche
Copy link
Member Author

cc @Platonn

devversion
devversion previously approved these changes Oct 9, 2024
Copy link
Member

@devversion devversion left a comment

Choose a reason for hiding this comment

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

Thanks @JeanMeche

@devversion devversion added action: merge The PR is ready for merge by the caretaker PullApprove: disable labels Oct 9, 2024
@JeanMeche JeanMeche marked this pull request as ready for review October 9, 2024 12:33
@devversion
Copy link
Member

Tests are failing 😞

@devversion devversion added action: cleanup The PR is in need of cleanup, either due to needing a rebase or in response to comments from reviews and removed action: merge The PR is ready for merge by the caretaker labels Oct 9, 2024
… the `bootstrap()` phase (angular#58112)

The `bootstrap()` phase might fail e.g. due to an rejected promise in some `APP_INIIALIZER`.
If `PlatformRef` is not destroyed, then the main app's injector is not destroyed and therefore `ngOnDestroy` hooks of singleton services is not called on the end (failure) of SSR.

This could lead to possible memory leaks in custom SSR apps, if their singleton services' `ngOnDestroy` hooks contained an important teardown logic (e.g. unsubscribing from RxJS observable).

Note: I needed to fix by the way another thing too: now we destroy `moduleRef` when `platformInjector` is destroyed - by setting a `PLATFORM_DESTROY_LISTENER`

Patch port of angular#58112
@devversion devversion added action: merge The PR is ready for merge by the caretaker and removed action: cleanup The PR is in need of cleanup, either due to needing a rebase or in response to comments from reviews labels Oct 9, 2024
@devversion
Copy link
Member

This PR was merged into the repository by commit b40875a.

The changes were merged into the following branches: 18.2.x

devversion pushed a commit that referenced this pull request Oct 9, 2024
… the `bootstrap()` phase (#58112) (#58135)

The `bootstrap()` phase might fail e.g. due to an rejected promise in some `APP_INIIALIZER`.
If `PlatformRef` is not destroyed, then the main app's injector is not destroyed and therefore `ngOnDestroy` hooks of singleton services is not called on the end (failure) of SSR.

This could lead to possible memory leaks in custom SSR apps, if their singleton services' `ngOnDestroy` hooks contained an important teardown logic (e.g. unsubscribing from RxJS observable).

Note: I needed to fix by the way another thing too: now we destroy `moduleRef` when `platformInjector` is destroyed - by setting a `PLATFORM_DESTROY_LISTENER`

Patch port of #58112

PR Close #58135
@devversion devversion closed this Oct 9, 2024
@JeanMeche JeanMeche deleted the server-destroy branch October 9, 2024 14:03
@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 Nov 9, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

action: merge The PR is ready for merge by the caretaker PullApprove: disable target: patch This PR is targeted for the next patch release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants