Unexpected finalization of uncancelable resource
See original GitHub issueScala version: 2.13.6 Cats-effect version: 3.2.9
Minimal example:
import cats.effect.{IO, IOApp, Resource}
import cats.effect.syntax.monadCancel._
object Main extends IOApp.Simple {
def resource(prefix: String): Resource[IO, Unit] =
Resource.makeCase(IO.unit) {
case (_, Resource.ExitCase.Succeeded) => IO.println(s"[$prefix]. Release. Success")
case (_, Resource.ExitCase.Errored(e)) => IO.println(s"[$prefix]. Release. Error: $e")
case (_, Resource.ExitCase.Canceled) => IO.println(s"[$prefix]. Release. Canceled")
}
def run: IO[Unit] =
for {
r1 <- resource("general").use(_ => IO.raiseError(new RuntimeException("oops"))).attempt
// emulate error
r2 <- resource("uncancelable").uncancelable.use(_ => IO.raiseError(new RuntimeException("oops"))).attempt
// emulate cancelation
d <- IO.deferred[Unit]
fiber <- resource("uncancelable cancel").uncancelable.use(_ => d.complete(()) >> IO.never).start
_ <- d.get // wait till `use` hit `never`
_ <- fiber.cancel
_ <- IO.println("r1: " + r1)
_ <- IO.println("r2: " + r2)
} yield ()
}
The output:
[general]. Release. Error: java.lang.RuntimeException: oops
[uncancelable]. Release. Success
[uncancelable cancel]. Release. Success
r1: Left(java.lang.RuntimeException: oops)
r2: Left(java.lang.RuntimeException: oops)
For some reason, a resource that has been marked as uncancelable
always has ExitCase.Succeeded
during the release stage. Even though it has been canceled or completed with an error.
Resource.uncancelable[IO, Unit](_ => resource("uncancelable"))
has the same behavior.
Issue Analytics
- State:
- Created 2 years ago
- Comments:9 (9 by maintainers)
Top Results From Across the Web
Unexpected finalization of uncancelable resource - bytemeta
For some reason, a resource that has been marked as uncancelable always has ExitCase.Succeeded during the release stage. Even though it has been...
Read more >cats-effect/Hotswap.scala at series/3.x · typelevel/cats-effect · GitHub
The newly acquired resource is returned and is released either when the [[Hotswap]] is. * finalized or upon the next call to [[swap]],...
Read more >Cancel subscriptions | Stripe Documentation
After all settings are finalized, click Cancel subscription. ... This occurs to prevent unexpected automatic payment attempts and reminder emails.
Read more >Resource Safety - Monix BIO
Running finalizer. guarantee ensures that we run the provided finalizer regardless of the exit condition, be it successful completion, failure, or cancellation.
Read more >Messages ING001I to INGY1337I - IBM
Operator response. Specify the fully qualified resource name and reissue the command. ... ING070E UNEXPECTED RESPONSE FROM system RC return code ...
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
If nobody objects, I’m going to have a go at this. I haven’t really dealt with
Resource
internals before so it should be interesting 😅Give it a shot! 😃 Really this is about implementing an
allocatedFull
that is dual toapplyFull