Skip to content
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

[DI] DI fails to throw an exception when DI tried to create an actor with missing constructor parameter #5734

Closed
Arkatufus opened this issue Mar 18, 2022 · 2 comments
Labels
bug-reproduction Used to reproduce bugs. won't fix

Comments

@Arkatufus
Copy link
Contributor

Arkatufus commented Mar 18, 2022

Version Information
Version of Akka.NET? 1.4.35
Which Akka.NET Modules? Akka.DependencyInjection

Describe the bug
Originally posted in stackoverflow
DI fails to throw an exception when DI tried to create an actor with missing constructor parameter. ie. the constructor parameter was not provided both in the props parameter and does not exist in the service provider.

To Reproduce
Steps to reproduce the behavior:
Reproduction spec: #5735

Expected behavior
ActorSystem.ActorOf() should throw when DI failed to instantiate the actor class

Actual behavior
ActorSystem.ActorOf() returned an IActorRef with a null actor inside its ActorCell

@Arkatufus
Copy link
Contributor Author

After reviewing the actor creation code and design, this is found to be not a bug.
Actor creation in Akka.NET happens as a 2 step process:

  1. An empty actor holder is returned by the ActorOf method, this holder contains the Mailbox and ActorCell. ActorCell contains the Props needed by the system to re/create the actor as needed.
  2. A Create system message is enqueued into the Mailbox, triggering the actual Actor instantiation.

This is essentially a "bubble" where the actor code lives, any exception thrown by any code at step 2 onward are blocked from propagating to the application layer and instead propagated up the chain of actors above it, letting them decide on what would happen to the faulting actors. Since the DI exception happened on step 2 of the process, the exception would never reach the code that actually calls the ActorOf method and instead be propagated up to the guardian actor and be logged as an error in the log.

@lnodaba
Copy link

lnodaba commented May 24, 2022

Yeah actually you can catch it with a supervisior, I figured that out and then it can be logged or handled in some way, that is already helping a lot:

.WithSupervisorStrategy(new OneForOneStrategy(receivedException =>
                {
                    _logger.LogError("Eror: {exception}", receivedException);
                    return Directive.Escalate;
                }));

This article has some example about it. https://getakka.net/articles/concepts/supervision.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug-reproduction Used to reproduce bugs. won't fix
Projects
None yet
Development

No branches or pull requests

2 participants