JavaSerializationException for persistAsync(ReceiveTimeout)

I’m migrating an application from Akka 2.5.32 to 2.6.20 and getting a JavaSerializationException when I pass to persistAsync()

[] [DisabledJavaSerializer(akka://MetricsSpec)] - Outgoing message attempted to use Java Serialization even though ` = off` was set! Message type was: [class$]
[ERROR] [] [akka://MetricsSpec@] - Rejected to persist event type [$] with sequence number [2] for persistenceId [/fsms/worktypes/str1__1] due to [Attempted to serialize message using Java serialization while `` was disabled. Check WARNING logs for more details.].
akka.serialization.DisabledJavaSerializer$JavaSerializationException: Attempted to serialize message using Java serialization while `` was disabled. Check WARNING logs for more details.

The serialization config for this test is

serializers {
      akka-persistence-message = "akka.persistence.serialization.MessageSerializer"
      akka-persistence-snapshot = "akka.persistence.serialization.SnapshotSerializer"
serialization-bindings {
    "akka.persistence.serialization.Message" = akka-persistence-message
    "akka.persistence.serialization.Snapshot" = akka-persistence-snapshot

Is there additional config I need to add to serialize ReceiveTimeout since java serialization is off?

Edit: The docs say that “From Akka 2.6.0 the Akka serialization with Java serialization is disabled by default and Akka itself doesn’t use Java serialization for any of its internal messages.” so I’m confused why it’s attempting to use java serialization for an Akka message.

I don’t think there is a serializer that can serialize ReceiveTimeout out of the box, while the old Java Serialization could serialize anything you’d throw at it.

Note that ReceiveTimeout is meant as a timeout signal, it is only sent locally to the actor itself and it does not contain any additional information on top of the fact that an actor did not get a message within the timeout it set, so it does not generally make sense to serialize.

If you still want to store the ReceiveTimeout you will likely have to add a serialization binding explicilty for in your configuration for it to be serialized with the serializer you have chosen (as shown in the docs here for Jackson for example ).

Thanks very much for the response. The context for why I was passing ReceiveTimeout to persistAsync was to avoid a race condition with any in-progress persistAsync callbacks.

I’ve created a case class to get persisted in place of ReceiveTimeout and have been able to serialize that with protobuf.

That sounds like a better solution indeed. :+1:

1 Like