views:

233

answers:

1

Calling the !! method from one actor to another worker actor appears to keep the channel open even after the reply was received by the caller (ie: future is ready).

For example, using !! to send 11 different messages from one actor to another worker actor will result in 11 messages similar to the below being shown in the mailbox of the original caller, each with a different Channel@xxxx value.

!(scala.actors.Channel@11b456f,Exit(com.test.app.actor.QueryActor@4f7bc2,'normal))

Are these messages awaiting replies from the worker, as the original caller is sending an Exit message out upon it's own call to exit(), or are they generated on the other end, and for some reason have the print form shown above? By this point, the worker actor has already exited, so the original caller of !! will definitely never receive any replies.

This behavior is undesirable, as the original calling actor's mailbox fills with these exit messages (one for each channel created for each time !! was used).

How can this be stopped? Is the original caller automatically "linking" to the reply channels created on each !! call?

+4  A: 

The reason why these Exit messages are sent to the original caller is that the caller links its temporary channel, which is used to receive the future result, to the callee. In particular, if the channel receives an exit signal, an Exit message is sent on that channel, which results in a message similar to what you describe to be sent to the actual caller (you can think of channels as tags on messages). This is done to allow (re-)throwing an exception inside the caller if the callee terminates before serving the future message send (the exception is thrown upon accessing the future).

The problem with the current implementation is that the caller receives an Exit message even if the future was already resolved. This is clearly a bug that should be filed on the Scala Trac. A possible fix is to only send an Exit message if the future has not been resolved, yet. In this case the Exit message will be removed whenever the future is accessed for the first time using apply or isSet.

Philipp Haller
Looks like when the future is created it gets linked to the actor that's going to provide the value. When the value is set, I think it needs to unlink. That would prevent all these messages. Also, the buildup in the links list is essentially a memory leak.
Erik Engbrecht
Scala ticket was made by Mr. Engbrechthttps://lampsvn.epfl.ch/trac/scala/ticket/3102
scaling_out
@scaling_out Philipp has now closed the ticked. It should be available on the next Scala trunk nightly, or the next Scala beta.
Daniel