Exception from receiveRecover should stop the PersistentActor #24192
This commit is contained in:
parent
9a13704969
commit
6fa74789ce
2 changed files with 19 additions and 2 deletions
|
|
@ -7,7 +7,7 @@ package akka.persistence
|
|||
import java.util.UUID
|
||||
import java.util.concurrent.atomic.AtomicInteger
|
||||
|
||||
import akka.actor.{ ActorCell, DeadLetter, StashOverflowException }
|
||||
import akka.actor.{ Actor, ActorCell, DeadLetter, StashOverflowException }
|
||||
import akka.annotation.InternalApi
|
||||
import akka.dispatch.Envelope
|
||||
import akka.event.{ Logging, LoggingAdapter }
|
||||
|
|
@ -459,7 +459,13 @@ private[persistence] trait Eventsourced extends Snapshotter with PersistenceStas
|
|||
}
|
||||
|
||||
private val recoveryBehavior: Receive = {
|
||||
val _receiveRecover = receiveRecover
|
||||
val _receiveRecover = try receiveRecover catch {
|
||||
case NonFatal(e) ⇒
|
||||
try onRecoveryFailure(e, Some(e))
|
||||
finally context.stop(self)
|
||||
returnRecoveryPermit()
|
||||
Actor.emptyBehavior
|
||||
}
|
||||
|
||||
{
|
||||
case PersistentRepr(payload, _) if recoveryRunning && _receiveRecover.isDefinedAt(payload) ⇒
|
||||
|
|
|
|||
|
|
@ -663,6 +663,11 @@ object PersistentActorSpec {
|
|||
case Cmd(d) ⇒ persist(Evt(d))(updateState)
|
||||
}
|
||||
}
|
||||
|
||||
class ExceptionActor(name: String) extends ExamplePersistentActor(name) {
|
||||
override def receiveCommand = commonBehavior
|
||||
override def receiveRecover = throw new TestException("boom")
|
||||
}
|
||||
}
|
||||
|
||||
abstract class PersistentActorSpec(config: Config) extends PersistenceSpec(config) with ImplicitSender {
|
||||
|
|
@ -1176,6 +1181,12 @@ abstract class PersistentActorSpec(config: Config) extends PersistenceSpec(confi
|
|||
persistentActor ! "boom"
|
||||
expectTerminated(persistentActor)
|
||||
}
|
||||
|
||||
"stop actor when direct exception from receiveRecover" in {
|
||||
val persistentActor = namedPersistentActor[ExceptionActor]
|
||||
watch(persistentActor)
|
||||
expectTerminated(persistentActor)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue