Skip to content

Resource#allocate that fails produces reportFailure under timeout #4697

Description

@FireFoxIL

I have recently discovered a strange behaviour while trying to use .timeout on the Resource of the Client.run(_) from http4s. As I later investigated, the issue has nothing to do with http4s, ember or fs2.

//> using scala 3
//> using dep org.typelevel::cats-effect:3.7.1

import cats.effect.*
import cats.effect.syntax.temporal.*
import scala.concurrent.duration.*

object ReproMakeBug extends IOApp {
  override def run(args: List[String]): IO[ExitCode] =
    Resource
      .make(IO.raiseError[Unit](new RuntimeException("boom")))(_ => IO.unit)
      .timeout(300.millis)
      .use(_ => IO.unit)
      .handleErrorWith { e =>
        IO.println(s"[handled] ${e.getClass.getName}: ${e.getMessage}")
      }
      .as(ExitCode.Success)
}

This code produces two error mesages: one defined in the code and one by IOApp.reportFailure. For me this is strange, because the error is handled and I expect that reportFailure should not be called.

Code with eval doesn't produce such message:

//> using scala 3
//> using dep org.typelevel::cats-effect:3.7.1

import cats.effect.*
import cats.effect.syntax.temporal.*
import scala.concurrent.duration.*

object ReproEvalControl extends IOApp {

  override def run(args: List[String]): IO[ExitCode] =
    Resource
      .eval(IO.raiseError[Unit](new RuntimeException("boom")))
      .timeout(300.millis)
      .use(_ => IO.unit)
      .handleErrorWith { e =>
        IO.println(s"[handled] ${e.getClass.getName}: ${e.getMessage}")
      }
      .guarantee(IO.sleep(600.millis))
      .as(ExitCode.Success)
}

No activity

Activity on this issue will appear here.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions