Skip to content

IO.syncStep(n).unsafeRunSync() fails with StackOverflowError #4337

Description

@migesok

This code works for me on 3.5.7 but fails on 3.6.0 (OpenJDK 21 on M1 Mac OS):

import cats.effect.*
import cats.syntax.all.*

object Main extends App {
  val syncStepSize = 1000000

  val io = for {
    ref <- Ref.of[IO, Int](0)
    _ <- Vector.fill(100000)(1).traverse_[IO, Unit](n => ref.update(_ + n))
    result <- ref.get
  } yield result

  println(io.syncStep(syncStepSize).unsafeRunSync())
}
Exception in thread "main" java.lang.StackOverflowError
	at cats.effect.IO$FlatMap.ioe(IO.scala:2235)
	at cats.effect.SyncStep$.interpret(IO.scala:2355)
	at cats.effect.SyncStep$.interpret(IO.scala:2356)
	at cats.effect.SyncStep$.interpret(IO.scala:2356)
	at cats.effect.SyncStep$.interpret(IO.scala:2356)
	at cats.effect.SyncStep$.interpret(IO.scala:2356)
	at cats.effect.SyncStep$.interpret(IO.scala:2356)
	at cats.effect.SyncStep$.interpret(IO.scala:2356)
        ...

I'm not sure if it's a bug or an expected behaviour. It was sure unexpected for me 😄

I tried to debug it a little bit but got lost in syncStep and SyncIO implementations.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions