Skip to content

fix(core): avoid injecting ErrorHandler from a destroyed injector #61886

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

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

Conversation

arturovt
Copy link
Contributor

@arturovt arturovt commented Jun 4, 2025

This commit prevents lazy injection of the internal ErrorHandler from a destroyed injector, as it would result in another "destroyed injector" error.

@pullapprove pullapprove bot requested a review from atscott June 4, 2025 23:52
@angular-robot angular-robot bot added the area: core Issues related to the framework runtime label Jun 4, 2025
@ngbot ngbot bot added this to the Backlog milestone Jun 4, 2025
@arturovt arturovt force-pushed the fix/avoid-errorHandler-inject branch from 464cf17 to 1c1bc54 Compare June 5, 2025 11:18
@arturovt arturovt force-pushed the fix/avoid-errorHandler-inject branch from 1c1bc54 to 1f55347 Compare June 5, 2025 17:11
@angular-robot angular-robot bot requested a review from atscott June 5, 2025 17:11
@atscott
Copy link
Contributor

atscott commented Jun 5, 2025

I'm not sure that swallowing the error is the correct behavior. If errors are happening in the application after it was destroyed, I don't know that the correct behavior is to swallow the error entirely.

@arturovt
Copy link
Contributor Author

arturovt commented Jun 5, 2025

Since the error handler isn’t available, can we re throw the error in a micro task or setTimeout?

@atscott
Copy link
Contributor

atscott commented Jun 5, 2025

Since the error handler isn’t available, can we re throw the error in a micro task or setTimeout?

Yea, I think that would be appropriate. I think setTimeout might be the better of the two

@arturovt arturovt force-pushed the fix/avoid-errorHandler-inject branch from 1f55347 to 20e744e Compare June 5, 2025 22:04
Comment on lines +87 to +94
inject(ApplicationRef).onDestroy(() => {
// Note: The unit test environment differs from the real browser environment.
// This is a simple test that ensures that if an error event is dispatched
// during destruction, it does not attempt to inject the `ErrorHandler`.
// Before the `if (injector.destroyed)` checks were added, this would
// throw a "destroyed injector" error.
dispatched = window.dispatchEvent(new Event('error'));
});
Copy link
Contributor

Choose a reason for hiding this comment

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

This actually came up today that the injector is marked as destroyed before the onDestroy hooks are invoked. I'm wondering if we want to change that behavior so onDestroy hooks still have the ability to use the injector since it's really not fully destroyed yet.

Can this change to account for the potential change above and dispatch the error event in a promise or timeout instead?

@arturovt arturovt force-pushed the fix/avoid-errorHandler-inject branch from 20e744e to 1a66a21 Compare June 5, 2025 23:13
@thePunderWoman thePunderWoman added action: merge The PR is ready for merge by the caretaker target: patch This PR is targeted for the next patch release labels Jun 6, 2025
@thePunderWoman
Copy link
Contributor

@arturovt Looks like you have one failing test you'll need to fix.

@pkozlowski-opensource pkozlowski-opensource 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 Jun 6, 2025
@arturovt arturovt force-pushed the fix/avoid-errorHandler-inject branch from 1a66a21 to 613d146 Compare June 6, 2025 11:27
Copy link
Contributor

@atscott atscott left a comment

Choose a reason for hiding this comment

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

Setting review to request changes so it doesn’t appear that I’ve approved

@arturovt arturovt force-pushed the fix/avoid-errorHandler-inject branch from 613d146 to f1e13e2 Compare June 6, 2025 12:40
This commit prevents lazy injection of the internal `ErrorHandler` from a destroyed injector, as it would result in another "destroyed injector" error.
@arturovt arturovt force-pushed the fix/avoid-errorHandler-inject branch from f1e13e2 to 1d437de Compare June 6, 2025 21:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
action: cleanup The PR is in need of cleanup, either due to needing a rebase or in response to comments from reviews area: core Issues related to the framework runtime target: patch This PR is targeted for the next patch release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants