typelevel / typelevel/cats-effect
`Resource.eval` extra cancellation point
Nobody has claimed this yet.
- 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:
- https://github.com/typelevel/cats-effect/blob/a48cac09ce5d236ff1e0857bc2e2722b3a6f82b1/kernel/shared/src/main/scala/cats/effect/kernel/Resource.scala#L193
- https://github.com/typelevel/cats-effect/blob/a48cac09ce5d236ff1e0857bc2e2722b3a6f82b1/kernel/shared/src/main/scala/cats/effect/kernel/Resource.scala#L527
The obvious fix, i.e., more investigation is needed.F.uncancelable { poll => poll(fa).flatMap(a => ...) makes a lot of existing law tests fail, so
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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