typelevel / typelevel/cats-effect

`Resource.eval` extra cancellation point

Open
#4,627 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

:beetle: bug
Dominant language
Scala
Stars
2.2k
Forks
576
Avg merge
2d 11h
Merged PRs (30d)
18

Description

As noticed during #4625, Resource.eval seems to have an extra cancellation point at the end. I think it shouldn't. Minimization:

    "Resource.eval" in real {
      val test = Resource
        .eval(IO.uncancelable(_ => IO.sleep(100.millis)))
        .timeout(10.millis)
        .use_
      test.as(ok)
    }

This fails with the 10.millis timeout. (Note: it passes with Resource.make.) Resource.eval is documented to "preserve interruptibility of fa". Which is very much uncancellable here. Yet, it is very much cancelled. (Or rather, it is cancelled right after the uncancelable ends, I think.) The crucial points in the code seem to be:

The obvious fix, i.e., F.uncancelable { poll => poll(fa).flatMap(a => ...) makes a lot of existing law tests fail, so more investigation is needed.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in kernel/shared/src/main/scala/cats/effect/kernel/Resource.scala at the referenced lines around 193 and 527, then run the minimized Resource.eval timeout case. Compare its cancellation behavior with Resource.make and run the existing law tests. Done means the extra cancellation point is resolved without breaking those law tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
scala
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.