Resource runs its finalizers when timed out#4617
Conversation
|
Can we make this so that it doesn't regress #4059? The reason IO.ref(false) flatMap { fired =>
val program = Resource.eval(IO.sleep(100.millis).onCancel(fired.set(true)).timeout(100.millis).use_
program.attempt flatMap {
case Left(()) => program // worked but we didn't reproduce the error
case Right(_) => fired.get.flatMap(f => IO(assert(f == true)))
}
}The above will almost certainly fail with your fix, indicating a memory leak in the case where the timeout executes but we don't run the finalizer. (also note the above is a handwave due to the way I encoded the repetition; with a proper implementation it would loop forever, so this isn't a real unit test) Edit: Additionally, this only fixes half of the problem. We also need to address the bug in |
|
Tick the box to add this pull request to the merge queue (same as
|
|
Oh, secondarily: can we retarget this at |
This fixes #4489 that was introduced by #4059 using an approach documented by @durban in #4489 (comment) and admitted reluctantly by @djspiewak in #4489 (comment) who suggests that there is perhaps a more general solution by rethinking Resource itself.