Skip to content

Object initialization with dependency via case class deadlocks #7960

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

Closed
laurynaslubys opened this issue Jan 10, 2020 · 2 comments · Fixed by #10041
Closed

Object initialization with dependency via case class deadlocks #7960

laurynaslubys opened this issue Jan 10, 2020 · 2 comments · Fixed by #10041
Assignees

Comments

@laurynaslubys
Copy link

minimized code

import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.duration._
import scala.concurrent.{Await, Future}

class A() {
  val bc = B.C(50)
}

object A {
  Thread.sleep(100L)

  val a = new A()
}


object B {
  Thread.sleep(100L)

  case class C(a: Int)

  val a: A = A.a
}

object Repro {
  final def main(args: Array[String]): Unit = {
    Await.result(Future.sequence(Seq(
      Future { A.a },
      Future { B.a },
    )), 1.seconds)
  }
}
Compilation output
[error] Exception in thread "main" java.util.concurrent.TimeoutException: Future timed out after [1 second]

expectation

I would expect initialization to not deadlock. This snippet does not deadlock in scala 2.x.

The sleeps are there just to make the issue more easily reproducible, without it the issue is still present, but intermittent.

I see no reason for the initialization to deadlock: initializing an instance of A does not require object B to be initialized as case class C does not reference any fields on object B.

@smarter smarter self-assigned this Jan 13, 2020
@griggt
Copy link
Contributor

griggt commented Oct 19, 2020

This may have been fixed by d65c0d9 in #9767. That is to say, I have been unable to get it to repro from that commit forward.

@smarter
Copy link
Member

smarter commented Oct 19, 2020

Seems likely, do you mind making a PR adding this testcase as a run test?

griggt added a commit to griggt/dotty that referenced this issue Oct 19, 2020
bishabosha added a commit that referenced this issue Oct 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants