Skip to content
This repository was archived by the owner on Feb 20, 2019. It is now read-only.
This repository was archived by the owner on Feb 20, 2019. It is now read-only.

Pickling - possible race condition? #40

Open
@tomasherman

Description

@tomasherman

Hey guys,

i have following problem:

i am trying to pickle this case class

trait GuiMessage
case class SkillMatrix(operators: Seq[String], skills: Seq[String], enabledSkills: Seq[(String,String)]) extends GuiMessage

The problem is that when i try to pickle this class from two different threads at the same time, i get following:

{x:Any => val pickled = x.asInstanceOf[SkillMatrix].pickle.value; println(s"pickling $x into $pickled");pickled}) //this function is called from two different threads
pickling SkillMatrix(List(1234, 4312),List(skill1, skill2),List((1234,skill1), (1234,skill2), (4312,skill1))) into {
  "tpe": "com.spinoco.horus.message.GuiMessage.SkillMessage.SkillMatrix",
  "operators": {
    "tpe": "scala.collection.Seq[java.lang.String]",
    "elems": [
      "1234",
      "4312"
    ]
  },
  "skills": {
    "tpe": "scala.collection.Seq[java.lang.String]",
    "elems": [
      "skill1",
      "skill2"
    ]
  },
  "enabledSkills": {
    "tpe": "scala.collection.Seq[scala.Tuple2[java.lang.String,java.lang.String]]",
    "elems": [
      { "$ref": 2 },
      {
      "tpe": "scala.Tuple2[java.lang.String,java.lang.String]",
      "a": "1234",
      "b": "skill2"
    },
      { "$ref": 4 }
    ]
  }
}
pickling SkillMatrix(List(1234, 4312),List(skill1, skill2),List((1234,skill1),(1234,skill2),(4312,skill1))) into {
  "tpe": "com.spinoco.horus.message.GuiMessage.SkillMessage.SkillMatrix",
  "operators": {
    "tpe": "scala.collection.Seq[java.lang.String]",
    "elems": [
      "1234",
      "4312"
    ]
  },
  "skills": {
    "tpe": "scala.collection.Seq[java.lang.String]",
    "elems": [
      "skill1",
      "skill2"
    ]
  },
  "enabledSkills": {
    "tpe": "scala.collection.Seq[scala.Tuple2[java.lang.String,java.lang.String]]",
    "elems": [
      {
      "tpe": "scala.Tuple2[java.lang.String,java.lang.String]",
      "a": "1234",
      "b": "skill1"
    },
      { "$ref": 3 },
      {
      "tpe": "scala.Tuple2[java.lang.String,java.lang.String]",
      "a": "4312",
      "b": "skill1"
    }
    ]
  }
}

as you can see, there are some really odd "$ref"s that i don't care for. Am i doing something wrong or is that error on your end? To me, it looks like some kind of race condition when pickling same object in two places at the same time.

Thanks

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions