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.
Comment on lines +107 to +113
return {
hasNavigationError,
redirectTo: undefined,
// TODO(alanagius): let's think on the content?
// or should we use `Promise.resolve('...')`?
content: () => Promise.reject(new Error('Application was destroyed during bootstrapping')),
};
Copy link
Collaborator

Choose a reason for hiding this comment

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

You could change the return type of this function to

): Promise<
  | { hasNavigationError: boolean; redirectTo?: string; content: () => Promise<string> }
  | { hasNavigationError: true }
> {

and change the return to

Suggested change
return {
hasNavigationError,
redirectTo: undefined,
// TODO(alanagius): let's think on the content?
// or should we use `Promise.resolve('...')`?
content: () => Promise.reject(new Error('Application was destroyed during bootstrapping')),
};
return {
hasNavigationError: true
};

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.

2 participants