Switched from 2.6.5 to 2.6.6 and I get the following error when I use context.log.It started working again after I removed the log statement. Was that use incorrect? Thanks for 2.6.6, especially with the SplitBrainResolver.
2020-06-13T08:12:40.692+0000 ERROR <.api-akka.actor.default-dispatcher-178> [dispatch.Dispatcher] Unsupported access to ActorContext from the outside of Actor[akka://api/system/singletonManagerapi/api#664341361]. No message is currently processed by the actor, but ActorContext was called from Thread[api-akka.cluster-dispatcher-21,5,main].
java.lang.UnsupportedOperationException: Unsupported access to ActorContext from the outside of Actor[akka://api/system/singletonManagerapi/api#664341361]. No message is currently processed by the actor, but ActorContext was called from Thread[api-akka.cluster-dispatcher-21,5,main].
at akka.actor.typed.internal.ActorContextImpl(ActorContextImpl.scala:317) ?[sd-0.1.jar:?]
at akka.actor.typed.internal.ActorContextImpl(ActorContextImpl.scala:305) ?[sd-0.1.jar:?]
at akka.actor.typed.internal.adapter.ActorContextAdapter(ActorContextAdapter.scala:49) ?[sd-0.1.jar:?]
at akka.actor.typed.internal.ActorContextImpl(ActorContextImpl.scala:161) ?[sd-0.1.jar:?]
at akka.actor.typed.internal.ActorContextImpl(ActorContextImpl.scala:160) ?[sd-0.1.jar:?]
at akka.actor.typed.internal.adapter.ActorContextAdapter(ActorContextAdapter.scala:49) ?[sd-0.1.jar:?]
Got the same problem where I was using ctx.log.info(…) from inside a stream which was running inside an actor.
The newly introduced error makes sense, but do you have any guidance on how you could do ad-hoc logging from inside an akka stream? This could also apply to any async callback where the callback is executing outside the normal message handling.
I was under impression that the Future’s callback which uses the actor’s ExecutionContext should be called by the actor’s scheduler, similar to a message, thread-safe to the actor’s state? Is it wrong assumption?
Is the “pipe to self” the only thread-safe way to schedule the callback to be able to mutate the actor’s state?
I was under impression that the Future’s callback which uses the actor’s ExecutionContext should be called by the actor’s scheduler, similar to a message, thread-safe to the actor’s state? Is it wrong assumption?
Yes, that assumption is wrong.
The only way to safely execute and touch mutable actor state is through a message. Using the context.executionContext/dispatcher only allows you to share the same dispatcher that the actor is using, any work scheduled there will still run independently of the actor.
pipeTo self of futures (and sometimes, when pipeTo is a bad fit, explicit tell in callbacks) is the safe way.