Hello,
I found a quite specific case involving Actors, Future callbacks and exceptions where self becomes deadLetters.
Am I doing something wrong or is it a bug?
Please see code and output below to reproduce/illustrate the issue.
Thanks, Fred
import akka.actor._
import scala.concurrent._
case object Done
case object Greet
case class Complete(p: Promise[Unit])
class Greeter extends Actor {
import context.dispatcher
def receive = {
case Done => println("Done (system still running)!")
case Complete(p) => p.success(())
case Greet =>
val p = Promise[Unit]()
val saveMyself = self
p.future onComplete {
case _ =>
println(s"self is $self")
println(s"self is expexted to be $saveMyself")
// cannot use self to send a message, bug?
self ! Done
saveMyself ! Done
}
self ! Complete(p)
throw new Exception("Messing with onComplete callback, self will be dead letters")
}
}
object HelloAkkaScala extends App {
val system = ActorSystem("helloakka")
val greeter = system.actorOf(Props[Greeter], "greeter")
greeter ! Greet
}
Program output :
Running HelloAkkaScala
self is Actor[akka://helloakka/deadLetters]
[ERROR] [06/18/2015 14:25:41.510] [helloakka-akka.actor.default-dispatcher-4] [akka://helloakka/user/greeter] Messing with onComplete callback, self will be dead letters
java.lang.Exception: Messing with onComplete callback, self will be dead letters
at Greeter$anonfun$receive$1.applyOrElse(HelloAkkaScala.scala:27)
at akka.actor.Actor$class.aroundReceive(Actor.scala:467)
at Greeter.aroundReceive(HelloAkkaScala.scala:8)
at akka.actor.ActorCell.receiveMessage(ActorCell.scala:516)
at akka.actor.ActorCell.invoke(ActorCell.scala:487)
at akka.dispatch.Mailbox.processMailbox(Mailbox.scala:238)
at akka.dispatch.Mailbox.run(Mailbox.scala:220)
at akka.dispatch.ForkJoinExecutorConfigurator$AkkaForkJoinTask.exec(AbstractDispatcher.scala:397)
at scala.concurrent.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:260)
at scala.concurrent.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1339)
at scala.concurrent.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1979)
at scala.concurrent.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:107)
self is expexted to be Actor[akka://helloakka/user/greeter#990239115]
Done (system still running)!
[INFO] [06/18/2015 14:25:41.516] [helloakka-akka.actor.default-dispatcher-3] [akka://helloakka/deadLetters] Message [Done$] from Actor[akka://helloakka/deadLetters] to Actor[akka://helloakka/deadLetters] was not delivered. [1] dead letters encountered. This logging can be turned off or adjusted with configuration settings 'akka.log-dead-letters' and 'akka.log-dead-letters-during-shutdown'.