nested actor creation failure

63 views
Skip to first unread message

Arjan Blokzijl

unread,
May 29, 2011, 3:34:22 AM5/29/11
to akka...@googlegroups.com
Hi all,

Last week I succesfully ported my project from akka 1.0 to 1.1. I was hit by one issue however: it appeared that in our application some actors were instantiated in the following way:

val nestedActor = actorOf(new OuterActor(actorOf(new InnerActor).start)).start

This works in 1.0, but fails in 1.1 with the error

Exception in thread "main" akka.actor.ActorInitializationException: ActorRef for instance of actor [org.ulysses.investing.routing.OuterActor] is not in scope.
You can not create an instance of an actor explicitly using 'new MyActor'.
You have to use one of the factory methods in the 'Actor' object to create a new actor.
Either use:
'val actor = Actor.actorOf[MyActor]', or
'val actor = Actor.actorOf(new MyActor(..))'


This is likely to be the result of this ticket: http://www.assembla.com/spaces/akka/tickets/757. As far as I could see, the reason for this is that the current implementation the initialization order is such that the actorRefInCreation threadlocal that is used to track the current ActorRef is first set twice, first by the ActorRef of OuterActor, and after that by the ActorRef of InnerActor. After creaton of the InnerActor the threadlocal is cleared, causing the subsequent initialization of OuterActor to fail.
This is fair enough, but to me it was not immediately apparent that the above code is invalid, since the actors seamed to be created the 'legal' way, and the error message was slightly confusing me.
To make a long story short: assuming that this is indeed the intended behaviour, can the error message and/or documentation be updated to include this case? This will save people running into the same issue some debugging time, I reckon.

Cheers, Arjan

√iktor Ҡlang

unread,
May 29, 2011, 4:55:05 AM5/29/11
to akka...@googlegroups.com
Hey Arjan,

Might be solvable if ActorRefInCreation is turned into a Stack[ActorRef] instead of just ActorRef.
But yes, it is because of the 757 ticket. I don't understand that your code as working, because my test-case showed the first ActorRef being reused by the second.

Cheers,


--
You received this message because you are subscribed to the Google Groups "Akka User List" group.
To post to this group, send email to akka...@googlegroups.com.
To unsubscribe from this group, send email to akka-user+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/akka-user?hl=en.



--
Viktor Klang

Akka Tech Lead
Typesafe - Enterprise-Grade Scala from the Experts

Twitter: @viktorklang

Arjan Blokzijl

unread,
May 29, 2011, 7:05:38 AM5/29/11
to akka...@googlegroups.com
Hi Viktor,

Yeah, probably 'working' is not the correct term here. Compiling and running might be a better way to describe it, though I have to have a look at it again as it seemed to run properly. In any case: do you want me to add a ticket for this?

Arjan

2011/5/29 √iktor Ҡlang <viktor...@gmail.com>

√iktor Ҡlang

unread,
May 29, 2011, 8:48:01 AM5/29/11
to akka...@googlegroups.com
Hi Arjan,

yeah, open a ticket for it. I can't promise that it's solvable, but atleast I'll try.

Arjan Blokzijl

unread,
May 29, 2011, 9:20:26 AM5/29/11
to akka...@googlegroups.com
Ok, created ticket #902

2011/5/29 √iktor Ҡlang <viktor...@gmail.com>

√iktor Ҡlang

unread,
Jun 2, 2011, 5:36:49 PM6/2/11
to akka...@googlegroups.com, Derek Wyatt
Hi,

I think I've fixed ticket #902, could you build the "release-1.2"-branch and verify?

Thanks,

Derek Wyatt

unread,
Jun 2, 2011, 5:38:02 PM6/2/11
to viktor...@gmail.com, akka...@googlegroups.com
It'll have to wait until tomorrow but I'll get on it first thing.

Thanks a lot!
Derek
--
Entered using opposable digits on my BlackBerry Torch
---------------------------------------------------------------------
This transmission (including any attachments) may contain confidential information, privileged material (including material protected by the solicitor-client or other applicable privileges), or constitute non-public information. Any use of this information by anyone other than the intended recipient is prohibited. If you have received this transmission in error, please immediately reply to the sender and delete this information from your system. Use, dissemination, distribution, or reproduction of this transmission by unintended recipients is not authorized and may be unlawful.

Derek Wyatt

unread,
Jun 3, 2011, 8:09:33 AM6/3/11
to √iktor Ҡlang, akka...@googlegroups.com
I haven't done any exhaustive testing yet to see if there are any interesting artifacts that have emerged, but my main problem seems to have disappeared.

Nicely done, sir, and thanks!
Derek
________________________________________
From: √iktor Ҡlang [viktor...@gmail.com]
Sent: Thursday, June 02, 2011 5:36 PM
To: akka...@googlegroups.com; Derek Wyatt
Subject: Re: [akka-user] nested actor creation failure

Hi,

I think I've fixed ticket #902, could you build the "release-1.2"-branch and verify?

Thanks,


--
Viktor Klang

Akka Tech Lead
Typesafe<http://www.typesafe.com/> - Enterprise-Grade Scala from the Experts

Twitter: @viktorklang

√iktor Ҡlang

unread,
Jun 3, 2011, 10:16:43 AM6/3/11
to Derek Wyatt, akka...@googlegroups.com
Great, I'll close the ticket and apply the fix for master as well.

Thanks,

2011/6/3 Derek Wyatt <dwy...@rim.com>



--
Typesafe - Enterprise-Grade Scala from the Experts

Twitter: @viktorklang

Thomas Themel

unread,
Jun 6, 2011, 4:17:44 AM6/6/11
to akka...@googlegroups.com
Hi,

Am Sonntag, 29. Mai 2011 09:34:22 UTC+2 schrieb Arjan Blokzijl:
Exception in thread "main" akka.actor.ActorInitializationException: ActorRef for instance of actor [org.ulysses.investing.routing.OuterActor] is not in scope.
You can not create an instance of an actor explicitly using 'new MyActor'.
You have to use one of the factory methods in the 'Actor' object to create a new actor.
Either use:
'val actor = Actor.actorOf[MyActor]', or
'val actor = Actor.actorOf(new MyActor(..))'

Another use case where this seems to break (at least I unexpectedly ran into the same error just now) is if one uses EventHandler to log during Actor initialization (or probably sends any actor message?).

ciao,
Thomas

rkuhn

unread,
Jun 6, 2011, 5:17:03 AM6/6/11
to akka...@googlegroups.com
Is it incidentally the case that the EventHandler call in question was the first one during the application life time? Because only then are the EventHandler listeners (i.e. actors) created.

Regards,

Roland

√iktor Ҡlang

unread,
Jun 6, 2011, 10:36:11 AM6/6/11
to akka...@googlegroups.com

Have you've verified against the release-1.2 branch?

Cheers,

 

ciao,
Thomas

--
You received this message because you are subscribed to the Google Groups "Akka User List" group.
To view this discussion on the web visit https://groups.google.com/d/msg/akka-user/-/ZU1sdmNBcGxLS0lK.

To post to this group, send email to akka...@googlegroups.com.
To unsubscribe from this group, send email to akka-user+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/akka-user?hl=en.
Reply all
Reply to author
Forward
0 new messages