-
Notifications
You must be signed in to change notification settings - Fork 14
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
investigate possible serialization regression(s) in 2.13 milestones #562
Comments
@kailuowang did cats hit something in this area, or am I misremembering? |
@SethTisue I am sorry I don't quite remember either, I quickly checked the PR I added 2.13 support for cats and didn't find any mention of serialization. |
There was an issue with shapeless which I worked around by suppressing a couple of tests. See discussion here: scala/scala#6729 (comment). |
for any given project, it's useful to know whether the problem goes away with |
I think these are different problems (scala/scala-xml#254, typelevel/scalacheck#427 (comment)) see my reproduce example scala/scala-xml#254 (comment). scala-xml test fail whether |
@kailuowang found it! typelevel/cats#2360 |
Looks like that is the community build showing the ScalaCheck bug, but in Cats's test suite? |
It's not mentioned yet here so I'll link to an existing issue surrounding Java serialization, List, and sbt's layered class loader - scala/bug#9237 (SI-9237) "Can't deserialize scala.List[M] if scala-library is not in the same classloader as M" (see also https://bugs.openjdk.java.net/browse/JDK-4340158 and sbt/sbt#89) @retronym foretold this in scala/collection-strawman#523:
Here's the reproduction of scala/bug#9237 modified to Scala 2.13.0-M5 and JUnit: https://github.com/eed3si9n/minimized-list-serialization/blob/v0.1.0/src/test/scala/issue/IssueTest.scala running
This is caused by workaround 1: fork the test and/or runIf you use Java serialization, fork your test.
Would that work? workaround 2: custom ObjectInputStreamAs a workaround, when possible you can use a custom Using that deserialize would look like this: def deserialize[A <: Serializable: ClassTag](bytes: Array[Byte]): A = {
val s = new ByteArrayInputStream(bytes)
val is = ScalaObjectInputStream[A](s)
is.readObject
} If your code is the one calling the deserialization that might be ok, but I'm guessing that's not always the case. workaround 3: provide alternative class loader for sbtThe other workaround might be to provide an alternative flatter class loader for sbt. |
About the other issue reported by Yoshida-san. To minimize class MyCollection[B](val list: List[B]) extends scala.collection.Iterable[B] {
override def iterator = list.iterator
// protected[this] override def writeReplace(): AnyRef = this
} I'm breaking up the test into the following steps: @Test
def testMyCollection: Unit = {
val list = List(1, 2, 3)
val arr = serialize(new MyCollection(list))
val obj2 = deserialize[MyCollection[Int]](arr)
assert(obj2.list == list)
} When I run this the error I get is as follows:
In other words, I don't get to the assertion, but instead it's failing at casting in the deserialization which deserialized what's going on?scala/scala#6676 makes trait Iterable[+A] extends IterableOnce[A] with IterableOps[A, Iterable, Iterable[A]] with Serializable { with protected[this] def writeReplace(): AnyRef = new DefaultSerializationProxy(iterableFactory.iterableFactory, this) In other words, the serialization of all things Iterable are passed into |
These are great write-ups! Sounds like the first issue can be carried forward in SI-9237. For the second issue, should a new bug ticket be created so it can be tracked? |
@ashawley Thanks. Yea. The added context is that Scala 2.13 adopts Serialization Proxy pattern, so it became all collection problem, not just List? I opened scala/bug#11192 for the second issue. |
I also hit a similar issue when serializing Vector. It seems scala.collection.generic.DefaultSerializationProxy is wrongly involved during serialization targets:
|
@eed3si9n workaround 2 (custom serializer) is not ideal because, for example, Spark uses its own serializer (based on ObjectInputStream of Java) for sending closures to remote workers. It means almost all code in Spark will fail when using Scala 2.13.0-M5. Actually my above test cases are added for supporting Spark. I think we should add serialization/deserialization test cases that use ObjectInput/OutputStream against Scala collection classes (Maybe it's already addressed in scala/bug#11192) |
@xerial If the issue goes away if you fork the test, then you're hitting scala/bug#9237 (also known as sbt/sbt#89) as long as we are using Serialization Proxy pattern together with sbt, this will remain an issue unless we either fork or fix sbt. |
|
Created a minimization https://gist.github.com/xerial/58e14b21a4492d6f87765fe9bff4b61a and I'll file another ticket. Thanks. |
@eed3si9n I think there is still value in non-forked execution without the layered classpaths. The Java standard library will still be warmed up. And it doesn't require configuration of settings to specify the |
So if I understand the problem correctly, when we get to: private[this] def readObject(in: ObjectInputStream): Unit = {
val in2 = in match {
case in: ScalaObjectInputStream => in
case _ => new ScalaObjectInputStream(in)
}
// rest of the method as before but replacing "in" by "in2"
} |
I'm suddenly seeing a bunch of serialization failures running
Also,
Although I saw some issues earlier this seems more severe: I've just updated my JDK to 1.8.0_192 ... could that be relevant? |
Sorry I should have said, that's both Oracle and OpenJDK 1.8.0_192. |
Downgrading to OpenJDK 1.8.0_181 doesn't help, so it's not the version bump. Is anyone else seeing this? |
I've been seeing it locally, yeah |
When did it start? Is there an existing issue for it (other than this one)? |
It started for me when I rebased my month-and-a-half-old |
I've been busy with Dotty for the last couple of weeks. My last successful |
new ticket on just the test failures in scala/scala: #569 |
ScalaTest was bitten, here: scalatest/scalatest#1423 |
closing because there are now separate tickets for everything that has turned up (most notably scala/bug#9237 and scala/bug#11192 and sbt/sbt#89) (#569 is now fixed) unless or until sbt moves to a flatter classloader structure for running test in-VM, people doing deserialization in their test suites will either have to use |
The text was updated successfully, but these errors were encountered: