question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

App + cats-effect hangs on 3.1.0 but works fine in 2.13.7

See original GitHub issue

This 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:closed
  • Created 2 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
SethTisuecommented, Jan 12, 2022

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.html

0reactions
djspiewakcommented, Jan 13, 2022

Sweet! 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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found