Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scala 2.12 serialization of Props #22041

Closed
patriknw opened this issue Dec 19, 2016 · 4 comments

Comments

Projects
None yet
2 participants
@patriknw
Copy link
Member

commented Dec 19, 2016

WIth Scala 2.12 the recommendation in http://doc.akka.io/docs/akka/2.4/scala/actors.html#Recommended_Practices doesn't work for remote deployment because Function is no longer serializable. It's translated to a lambda, which is not serializable. E.g. error message:

[JVM-2] [ERROR] [12/19/2016 08:42:49.917] [NewRemoteActorSpec-akka.remote.default-remote-dispatcher-14] [akka.remote.Remoting] akka.remote.NewRemoteActorSpec$$$Lambda$459/1116094714
[JVM-2] java.lang.ClassNotFoundException: akka.remote.NewRemoteActorSpec$$$Lambda$459/1116094714
[JVM-2] 	at java.lang.Class.forName0(Native Method)
[JVM-2] 	at java.lang.Class.forName(Class.java:348)
[JVM-2] 	at akka.actor.ReflectiveDynamicAccess.$anonfun$getClassFor$1(ReflectiveDynamicAccess.scala:21)
[JVM-2] 	at akka.actor.ReflectiveDynamicAccess$$Lambda$135/251210093.apply(Unknown Source)
[JVM-2] 	at scala.util.Try$.apply(Try.scala:209)
[JVM-2] 	at akka.actor.ReflectiveDynamicAccess.getClassFor(ReflectiveDynamicAccess.scala:20)
[JVM-2] 	at akka.remote.serialization.DaemonMsgCreateSerializer.deserialize(DaemonMsgCreateSerializer.scala:118)
[JVM-2] 	at akka.remote.serialization.DaemonMsgCreateSerializer.$anonfun$fromBinary$1(DaemonMsgCreateSerializer.scala:103)
[JVM-2] 	at akka.remote.serialization.DaemonMsgCreateSerializer$$Lambda$469/936208452.apply(Unknown Source)

For actors that are to be remote deployed the class based Props must be used:

Props(classOf[SomeActor], someConstructorParam)
@patriknw

This comment has been minimized.

Copy link
Member Author

commented Dec 19, 2016

The generated lambdas are serializable if the requested SAM is. For scala.FunctionN, lambdas are always serializable. The problem we are seeing here is that the lambda is serialized as the top level object and for that we try to load the class with the generated lambda name. It works if I wrap the function in another Serializable class, e.g.

 case class Foo(fun: Function1[Int, Int])

We might be able to use that trick for the Props(new SomeActor) case also.

patriknw added a commit that referenced this issue Dec 20, 2016

@patriknw patriknw self-assigned this Dec 20, 2016

@patriknw patriknw added this to the 2.4.17 milestone Dec 20, 2016

patriknw added a commit that referenced this issue Dec 20, 2016

patriknw added a commit that referenced this issue Jan 5, 2017

patriknw added a commit that referenced this issue Jan 20, 2017

patriknw added a commit that referenced this issue Jan 23, 2017

Merge pull request #22044 from akka/wip-22041-ser-fun-patriknw
serialize Scala 2.12 functions when used in remote deployment, #22041

patriknw added a commit that referenced this issue Jan 23, 2017

patriknw added a commit that referenced this issue Jan 23, 2017

Merge pull request #22181 from akka/wip-22041-ser-fun-2.4-patriknw
serialize Scala 2.12 functions for when used in remote deployment, #22041 (for validation)

@patriknw patriknw closed this Jan 23, 2017

@JamesCarl

This comment has been minimized.

Copy link

commented Feb 11, 2017

As someone learning Akka this was a particularly tricky bug to identify when just getting started with remoting using Akka 2.4.16 and Scala version 2.12 a helpful note in the docs might increase adoption. Thank you for your work.

@patriknw

This comment has been minimized.

Copy link
Member Author

commented Feb 11, 2017

Sorry for the inconvenience. It was a bug and it should be fixed in 2.4.17 so documentation should now be correct again. Let us know if you observe any thing else.

@JamesCarl

This comment has been minimized.

Copy link

commented Feb 12, 2017

Ah, just saw the new release thank you again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.