slick / slick

Slick (Scala Language Integrated Connection Kit) is a modern database query and access library for Scala
https://scala-slick.org/
BSD 2-Clause "Simplified" License
2.65k stars 609 forks source link

java.lang.StackOverflowError when using reduceLeft on filter in high concurrency #1896

Open hongBry opened 6 years ago

hongBry commented 6 years ago

slick version is 3.2.1

Reported on postgres profiles.

i use reduceLeft in the filter clause, there may be a java.lang.StackOverflowError, if the Array reduced is too big(>30) in high concurrency. it will occur the StackOverflowError error.

Some stacktrace: java.lang.StackOverflowError at slick.compiler.AssignUniqueSymbols.tr$1(AssignUniqueSymbols.scala:55) at slick.compiler.AssignUniqueSymbols.$anonfun$apply$8(AssignUniqueSymbols.scala:56)

    at slick.ast.Apply.mapChildren(Node.scala:546)
    at slick.compiler.AssignUniqueSymbols.tr$1(AssignUniqueSymbols.scala:56)
    at slick.compiler.AssignUniqueSymbols.$anonfun$apply$8(AssignUniqueSymbols.scala:56)
    at slick.util.ConstArray.endoMap(ConstArray.scala:122)
    at slick.ast.Node.mapChildren(Node.scala:50)
    at slick.ast.Node.mapChildren$(Node.scala:48)
    at slick.ast.Apply.mapChildren(Node.scala:546)
    at slick.compiler.AssignUniqueSymbols.tr$1(AssignUniqueSymbols.scala:56)
    at slick.compiler.AssignUniqueSymbols.$anonfun$apply$8(AssignUniqueSymbols.scala:56)
    at slick.util.ConstArray.endoMap(ConstArray.scala:122)
    at slick.ast.Node.mapChildren(Node.scala:50)
    at slick.ast.Node.mapChildren$(Node.scala:48)
    at slick.ast.Apply.mapChildren(Node.scala:546)
    at slick.compiler.AssignUniqueSymbols.tr$1(AssignUniqueSymbols.scala:56)
    at slick.compiler.AssignUniqueSymbols.$anonfun$apply$8(AssignUniqueSymbols.scala:56)
    at slick.util.ConstArray.endoMap(ConstArray.scala:122)
    at slick.ast.Node.mapChildren(Node.scala:50)
    at slick.ast.Node.mapChildren$(Node.scala:48)
    at slick.ast.Apply.mapChildren(Node.scala:546)
    at slick.compiler.AssignUniqueSymbols.tr$1(AssignUniqueSymbols.scala:56)
    at slick.compiler.AssignUniqueSymbols.$anonfun$apply$8(AssignUniqueSymbols.scala:56)
hongBry commented 6 years ago

i found the fault. i use the ‘ls’ has same elem

val query = tPosts.filter{ p =>
  val a = ls.map{
    l =>
      p.elem1=== l._3 && p.emem2 === l._1 && p.elem3 === l._2
  }
  a.reduceLeft(_ || _)
}
db.run{query.result}

it will report the stackoverflowError