Cloud Stack Ninja

I am experiencing an issue with the example FSM from the classic actor documentation, an actor that accumulates messages together until a certain timeout is reached.

class BatchHandler(implicit inj: Injector)
  extends FSM[BatchHandler.State, BatchHandler.Data] with Injectable with AppLogging {

  private val batchTime: FiniteDuration = 10.seconds

  startWith(BatchHandler.Idle, BatchHandler.Uninitialized)

  when(BatchHandler.Idle) {
    case Event(BatchHandler.SetTarget(target), Uninitialized) =>
      stay.using(Todo(target, Vector.empty))

  onTransition {
    case Active -> BatchHandler.Idle =>
      stateData match {
        case Todo(target, queue) =>
          context.actorSelection(target) ! Batch(queue)
        case _                => // nothing to do

  when(Active, stateTimeout = batchTime) {
    case Event(Flush | StateTimeout, t: Todo) =>
      goto(BatchHandler.Idle).using(t.copy(queue = Vector.empty))

  whenUnhandled {
    // common code for both states
    case Event(BatchHandler.Queue(obj), t @ Todo(_, v)) =>
      goto(Active).using(t.copy(queue = v :+ obj))

    case Event(e, s) =>



The stateTimeout parameter for the Active state works for a few minutes, and I see the enqueued messages being sent to the target. After a while, the actor just stays in Active state and eventually flushes when it is around 2K messages, not respecting 10s timeout.

I am using akkaVersion = "2.5.23". I have found some issues in older versions, like this!topic/akka-user/NsAoqPZ2Svo but it is supposed to be fixed by now.

Read more here:

Content Attribution

This content was originally published by Leo Rodríguez at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: