Hi,
In some rare circumstances (I haven’t investigated it closer) I’m getting the following error when calling EventSourcedBehavior.lastSequenceNumber:
akka.actor.typed.internal.BehaviorImpl$ReceiveMessageBehavior
java.lang.IllegalStateException: Cannot extract the lastSequenceNumber in state akka.actor.typed.internal.BehaviorImpl$ReceiveMessageBehavior
at akka.persistence.typed.scaladsl.EventSourcedBehavior$.lastSequenceNumber(EventSourcedBehavior.scala:109)
at akka.persistence.typed.javadsl.EventSourcedBehavior.lastSequenceNumber(EventSourcedBehavior.scala:198)
The method lastSequenceNumber is called from the command handler (of EventSourcedBehavior) when creating effect chain with the following helper method:
protected EffectBuilder<Event, State> persist(List<Event> events) {
long lastSeqNr = lastSequenceNumber(this.ctx);
return Effect().persist(events).thenRun(s -> {
forEach(withPosition(events), (eventPos, event) -> {
long eventSeqNr = lastSeqNr + eventPos + 1;
logEvent(event, eventSeqNr);
});
});
}
Am I doing something wrong here?
Stacktrace below (akka 2.5.25):
03:00:03,898 ERROR [OneForOneStrategy] Cannot extract the lastSequenceNumber in state akka.actor.typed.internal.BehaviorImpl$ReceiveMessageBehavior
java.lang.IllegalStateException: Cannot extract the lastSequenceNumber in state akka.actor.typed.internal.BehaviorImpl$ReceiveMessageBehavior
at akka.persistence.typed.scaladsl.EventSourcedBehavior$.lastSequenceNumber(EventSourcedBehavior.scala:109)
at akka.persistence.typed.javadsl.EventSourcedBehavior.lastSequenceNumber(EventSourcedBehavior.scala:198)
at pl.newicom.jms.Eventsourced.persist(Eventsourced.java:80)
at pl.newicom.jms.execution.JobExecution.lambda$commandHandler$2(JobExecution.java:142)
at akka.persistence.typed.javadsl.CommandHandlerBuilderByState$$anon$7.apply(CommandHandler.scala:388)
at akka.persistence.typed.javadsl.EventSourcedBehavior.$anonfun$apply$3(EventSourcedBehavior.scala:172)
at akka.persistence.typed.internal.Running$HandlingCommands.onCommand(Running.scala:124)
at akka.persistence.typed.internal.Running$HandlingCommands.onMessage(Running.scala:108)
at akka.persistence.typed.internal.Running$HandlingCommands.onMessage(Running.scala:103)
at akka.actor.typed.scaladsl.AbstractBehavior.receive(AbstractBehavior.scala:59)
at akka.actor.typed.Behavior$.interpret(Behavior.scala:437)
at akka.actor.typed.Behavior$.interpretMessage(Behavior.scala:393)
at akka.actor.typed.internal.StashBufferImpl.interpretOne$1(StashBufferImpl.scala:133)
at akka.actor.typed.internal.StashBufferImpl.interpretUnstashedMessages(StashBufferImpl.scala:166)
at akka.actor.typed.internal.StashBufferImpl.unstash(StashBufferImpl.scala:117)
at akka.persistence.typed.internal.StashManagement.tryUnstashOne(StashManagement.scala:75)
at akka.persistence.typed.internal.StashManagement.tryUnstashOne$(StashManagement.scala:65)
at akka.persistence.typed.internal.Running.tryUnstashOne(Running.scala:91)
at akka.persistence.typed.internal.Running.$anonfun$storingSnapshot$2(Running.scala:382)
at akka.actor.typed.internal.BehaviorImpl$ReceiveMessageBehavior.receive(BehaviorImpl.scala:53)
at akka.actor.typed.Behavior$.interpret(Behavior.scala:437)
at akka.actor.typed.Behavior$.interpretMessage(Behavior.scala:393)
at akka.actor.typed.internal.InterceptorImpl$$anon$2.apply(InterceptorImpl.scala:52)
at akka.actor.typed.internal.WidenedInterceptor.aroundReceive(InterceptorImpl.scala:207)
at akka.actor.typed.internal.InterceptorImpl.receive(InterceptorImpl.scala:79)
at akka.actor.typed.Behavior$.interpret(Behavior.scala:437)
at akka.actor.typed.Behavior$.interpretMessage(Behavior.scala:393)
at akka.actor.typed.internal.InterceptorImpl$$anon$2.apply(InterceptorImpl.scala:52)
at akka.persistence.typed.internal.EventSourcedBehaviorImpl$$anon$1.aroundReceive(EventSourcedBehaviorImpl.scala:134)
at akka.actor.typed.internal.InterceptorImpl.receive(InterceptorImpl.scala:79)
at akka.actor.typed.Behavior$.interpret(Behavior.scala:437)
at akka.actor.typed.Behavior$.interpretMessage(Behavior.scala:393)
at akka.actor.typed.internal.InterceptorImpl$$anon$2.apply(InterceptorImpl.scala:52)
at akka.actor.typed.internal.SimpleSupervisor.aroundReceive(Supervision.scala:109)
at akka.actor.typed.internal.InterceptorImpl.receive(InterceptorImpl.scala:79)
at akka.actor.typed.Behavior$.interpret(Behavior.scala:437)
at akka.actor.typed.Behavior$.interpretMessage(Behavior.scala:393)
at akka.actor.typed.internal.adapter.ActorAdapter.handleMessage(ActorAdapter.scala:118)
at akka.actor.typed.internal.adapter.ActorAdapter.aroundReceive(ActorAdapter.scala:102)
at akka.actor.ActorCell.receiveMessage(ActorCell.scala:612)
at akka.actor.ActorCell.invoke(ActorCell.scala:581)
at akka.dispatch.Mailbox.processMailbox(Mailbox.scala:268)
at akka.dispatch.Mailbox.run(Mailbox.scala:229)
at akka.dispatch.Mailbox.exec(Mailbox.scala:241)
at akka.dispatch.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:260)
at akka.dispatch.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1339)
at akka.dispatch.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1979)
at akka.dispatch.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:107)
That is surprising, I think it it could be a bug, please open up an issue. If you have a reproducer that’d be great. Almost looks like the event sourced behavior switched to a non-eventsourced behavior and then tried to access the sequence number but that shouldn’t be possible.