Skip to content

fix(core): avoid injecting internal error handler from a destroyed injector #62275

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

arturovt
Copy link
Contributor

This commit prevents lazy injection of the internal ErrorHandler from a destroyed injector, which would otherwise result in a secondary "destroyed injector" error.

The handleUncaughtError function is used in a wrapped event listener that invokes the ErrorHandler if the listener throws. A simple case in a micro-frontend application:

onNavigationToAnotherApp() {
  this.appRef.destroy();
  do_some_stuff_ie_loggin_that_may_throw();
}

If the function throws an error, Angular attempts to inject the ErrorHandler from a destroyed injector.

@@ -699,7 +699,8 @@ export function handleUncaughtError(lView: LView, error: any): void {
if (!injector) {
return;
}
const errorHandler = injector.get(INTERNAL_APPLICATION_ERROR_HANDLER, null);
// TODO(atscott): should we re-throw an error in a `setTimeout` if injector is destroyed?
Copy link
Contributor Author

@arturovt arturovt Jun 25, 2025

Choose a reason for hiding this comment

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

@angular-robot angular-robot bot added the area: core Issues related to the framework runtime label Jun 25, 2025
@ngbot ngbot bot added this to the Backlog milestone Jun 25, 2025
…jector

This commit prevents lazy injection of the internal `ErrorHandler` from a destroyed injector, which would otherwise result in a secondary "destroyed injector" error.

The `handleUncaughtError` function is used in a wrapped event listener that invokes the `ErrorHandler` if the listener throws. A simple case in a micro-frontend application:

```ts
onNavigationToAnotherApp() {
  this.appRef.destroy();
  do_some_stuff_ie_loggin_that_may_throw();
}
```

If the function throws an error, Angular attempts to inject the `ErrorHandler` from a destroyed injector.
@arturovt arturovt force-pushed the fix/avoid-handleUncaught-inject branch from 13c53f1 to 4c49e1f Compare June 26, 2025 09:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: core Issues related to the framework runtime
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy