App + cats-effect hangs on 3.1.0 but works fine in 2.13.7
See original GitHub issueThis code
import cats.effect._
import cats.implicits._
import cats.effect.unsafe.implicits.global
object IOComposition extends App {
val hello = IO(println(s"[${Thread.currentThread.getName}] Hello"))
val world = IO(println(s"[${Thread.currentThread.getName}] World"))
val hw1: IO[Unit] = for {
_ <- hello
_ <- world
} yield ()
val hw2: IO[Unit] =
(hello, world).mapN((_, _) => ())
hw1.unsafeRunSync()
hw2.unsafeRunSync()
}
hangs with Scala 3.1.0 after printing only “Hello”
Compiling project (Scala 3.1.0, JVM)
Compiled project (Scala 3.1.0, JVM)
[io-compute-2] Hello
but works perfecty with Scala 2.13.7
Compiling project (Scala 2.13.7, JVM)
Compiled project (Scala 2.13.7, JVM)
[io-compute-2] Hello
[io-compute-4] World
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (5 by maintainers)
Top Results From Across the Web
Lambda in REPL (using object-wrappers) + concurrency ...
The following code is a test of generating and using java.util. ... App + cats-effect hangs on 3.1.0 but works fine in 2.13.7...
Read more >Migration Guide · Cats Effect - Typelevel
Here is an overview of the steps you should take to migrate your application to Cats Effect 3: Make sure your dependencies have...
Read more >Ammonite
The goal of Ammonite is to liberate your Scala code from heavyweight "projects", using the lightweight Ammonite runtime: if you want to run...
Read more >Application hangs with a simple Cats Effect IO example - Reddit
Hi all, I created a simple example with `IO.start` and the strange thing is that, if I run everything in my "Main", it...
Read more >What is the reason for IO application not closing its execution?
IO -based apps is using cats.effect.IOApp (or cats.effect. ... That means the main thread might finish but the other threads keep being ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I’d also be interested in knowing if the problem goes away if you avoid using
App
.App
is not recommended in Scala 3, as per https://docs.scala-lang.org/scala3/reference/changed-features/main-functions.htmlSweet! So this is definitely the
MethodHandle
concurrent initialization issue then. It’s actually part of the JVM itself and not really anything that either Scala or Cats Effect can address. In fact, you can reproduce this issue using bare Java.