Skip to content

Conversation

@arturovt
Copy link
Contributor

Fixes crash when platform/app destroys itself during the bootstrapping and stabilization phase. Previously, the code would call applicationRef.injector without checking if the platform was destroyed, resulting in: "Error: Injector has already been destroyed"

This can occur when:

  • Component constructor calls inject(PlatformRef).destroy()
  • AbortSignal triggers during request handling
  • APP_INITIALIZER rejects and causes cleanup
  • Custom guard/resolver logic destroys the platform

Solution: Check applicationRef.destroyed after whenStable() and return error state instead of accessing destroyed injector.

Test: Added test case that destroys app in component constructor to verify graceful handling of this edge case.

Fixes crash when platform/app destroys itself during the bootstrapping and
stabilization phase. Previously, the code would call `applicationRef.injector`
without checking if the platform was destroyed, resulting in:
"Error: Injector has already been destroyed"

This can occur when:
- Component constructor calls `inject(PlatformRef).destroy()`
- AbortSignal triggers during request handling
- APP_INITIALIZER rejects and causes cleanup
- Custom guard/resolver logic destroys the platform

Solution: Check `applicationRef.destroyed` after `whenStable()` and return error
state instead of accessing destroyed injector.

Test: Added test case that destroys app in component constructor to
verify graceful handling of this edge case.
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.

1 participant