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

Exception creating actor implementing IWithUnboundedStash #941

Closed
raypurchasett opened this issue May 2, 2015 · 13 comments
Closed

Exception creating actor implementing IWithUnboundedStash #941

raypurchasett opened this issue May 2, 2015 · 13 comments

Comments

@raypurchasett
Copy link
Contributor

When an actor that implements IWithUnboundedStash that was resolved from DIExt (autofac in this case, although I doubt that matters) calls it's first Become, this exception is thrown:

[ERROR][02/05/2015 23:54:32][Thread 0012][ActorSystem(System)] An exception occurred while trying to apply plugin of type Akka.Actor.ActorStashPlugin to the newly created actor (Type = Machina.
MessagePipeline.MessageBufferingActor, Path = akka://System/user/$b/$b)
Cause: System.NotSupportedException: DequeBasedMailbox required, got: UnboundedMailbox
An (unbounded) deque-based mailbox can be configured as follows:
    my-custom-mailbox {
        mailbox-type = "Akka.Dispatch.UnboundedDequeBasedMailbox"
    }
   at Akka.Actor.Internal.AbstractStash..ctor(IActorContext context, Int32 capacity)
   at Akka.Actor.Internal.UnboundedStashImpl..ctor(IActorContext context)
   at Akka.Actor.StashFactory.CreateStash(IActorContext context, Type actorType)
   at Akka.Actor.ActorStashPlugin.AfterIncarnated(ActorBase actor, IActorContext context)
   at Akka.Actor.ActorProducerPipeline.AfterActorIncarnated(ActorBase actor, IActorContext context)
@rogeralsing
Copy link
Contributor

As the exception complains about the mailbox type, have you configured the actor to use some custom mailbox type?

Not all mailboxes support stashing, as the mailbox has to be able to prepend messages at the front when using stashing.

@raypurchasett
Copy link
Contributor Author

I haven't changed the configuration of the mailbox type. It's just a vanilla ReceiveActor with no custom configuration.

This sample actor has the same issue with resolving through DI

   class TestActor : ReceiveActor, IWithUnboundedStash
    {
        public IStash Stash { get; set; }

        protected override void PreStart()
        {
            base.PreStart();
            Become(FirstState);
        }

        private void FirstState()
        {

        }
    }

When resolving it through

Context.ActorOf(Context.System.GetExtension<DIExt>().Props(typeof(TestActor)))

it errors, when creating it directly through

Context.ActorOf(Props.Create(() => new TestActor()));

it's fine

The registration in autofac is just:

builder.RegisterType<TestActor>().AsSelf();

Cheers

@Danthar
Copy link
Member

Danthar commented May 4, 2015

The problem is in the Akka.DI.Core.DIActorProducer.

 public Type ActorType
        {
            get { return this.dependencyResolver.GetType(); }
        }

It returns the type of the dependencyResolver instead of the ActorType. This causes the rest of the Actor Initialisation routine to fail to detect the IWithUnboundedStash and inject the wrong Mailbox type.

Aaronontheweb added a commit that referenced this issue May 6, 2015
@jcwrequests
Copy link

@Danthar Thanks for catching that one.

@DNosralla
Copy link

Still can't use IWithUnboundedStash actor from DI Context.

Akka.Actor.Internal.AbstractStash is trying to get:
var mailbox = actorCell.Mailbox as IDequeBasedMailbox

If actor is created from system directly, the actorCell.Mailbox is Akka.Dispatch.UnboundedDequeBasedMailbox, that is IDequeBasedMailbox.

If actor is created from DI (AutoFac), the actorCell.Mailbox is
Akka.Dispatch.UnboundedMailbox, wich does not resolve to IDequeBasedMailbox

Next it checks if the mailbox is not null, and throw the "DequeBasedMailbox required" exception.

@Danthar
Copy link
Member

Danthar commented May 7, 2015

A PR containing a fix got merged a short while ago. Have you tried it with a version including that fix? I believe nowadays we have nightlies on nuget but I'm not sure @Aaronontheweb (?)

-----Original Message-----
From: "DNosralla" [email protected]
Sent: ‎07/‎05/‎2015 05:59
To: "akkadotnet/akka.net" [email protected]
Cc: "Arjen Smits" [email protected]
Subject: Re: [akka.net] Exception creating actor implementingIWithUnboundedStash (#941)

Still can't use IWithUnboundedStash actor from DI Context.
Akka.Actor.Internal.AbstractStash is trying to get:
var mailbox = actorCell.Mailbox as IDequeBasedMailbox
If actor is created from system directly, the actorCell.Mailbox is Akka.Dispatch.UnboundedDequeBasedMailbox, that is IDequeBasedMailbox.
If actor is created from DI (AutoFac), the actorCell.Mailbox is
Akka.Dispatch.UnboundedMailbox, wich does not resolve to IDequeBasedMailbox
Next it checks if the mailbox is not null, and throw the "DequeBasedMailbox required" exception.

Reply to this email directly or view it on GitHub.

@DNosralla
Copy link

Yes, running the dev branch, including fix from #950
Just made a pull request with unit tests for it #955

(I have no idea about the compliance of my pull request or its contents, just wanted to make it easy for you to catch the problem)

@Danthar
Copy link
Member

Danthar commented May 7, 2015

I found it. Its a stupid typo in my last PR. Ill fix that asap.

@Danthar
Copy link
Member

Danthar commented May 18, 2015

A fix for this issue has been merged several days ago. Ergo this can be closed.

@Horusiath
Copy link
Contributor

From @mithril52 , Akka version 1.0.5 and Ninject DI:

If I try to create the actor like this:
`Context.ActorOf(Context.DI().Props(typeof(MdmSessionHandlerActor)), msg.DestinationAddress)'
It does work, and I get the stash properly. But if I try it via a bound interface like this:
'container.Bind<IMdmSessionHandler>().To<MdmSessionHandlerActor>();
It doesn't work
And I obviously need to figure out how to properly do markdown here...
After the above Bind call there should have been a line like this:
Context.ActorOf(Context.DI().Props(typeof(IMdmSessionHandler)), msg.DestinationAddress)

@Horusiath Horusiath reopened this Dec 24, 2015
@rogeralsing
Copy link
Contributor

@Horusiath same error different DI package?

@Horusiath
Copy link
Contributor

Sorry, my bad. Using container directly to creat an actor will always fail. Closing this.

@bonza
Copy link

bonza commented Feb 17, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants