-
Couldn't load subscription status.
- Fork 1.4k
Closed
Description
Reported by @alexandru here. This may be the same bug identified by @wi101.
Ah, you're right, so you are sequencing the execution of finalisers. Except that I found a bug, some sort of race condition.
Sample 1 — in which the inner finalizer never gets executed:
val task = IO.unit[Void].bracket[Unit] { _ =>
IO.sync[Void, Unit](println("start 1")) *> IO.sleep(1.second) *> IO.sync(println("release 1"))
} { _ =>
IO.unit[Void].bracket[Unit] { _ =>
IO.sync[Void, Unit](println("start 2")) *> IO.sleep(1.second) *> IO.sync(println("release 2"))
} { _ =>
IO.never[Void, Unit]
}
}
task.fork.flatMap(f => f.interrupt(new RuntimeException("cancel")) *> IO.never)
This fails with:
java.lang.Error: Defect: Fiber is not in executing or async state
at scalaz.ioeffect.RTS$FiberContext.enterAsyncStart(RTS.scala:931)
at scalaz.ioeffect.RTS$FiberContext.evaluate(RTS.scala:514)
at scalaz.ioeffect.RTS$FiberContext.$anonfun$fork$1(RTS.scala:761)
at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:12)
at scalaz.ioeffect.RTS$$anon$1.run(RTS.scala:117)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
start 1
release 1
Sample 2 — the first specified finalizer gets executed twice somehow, which is really odd:
IO.unit[Void]
.bracket[Unit](_ => IO.sync[Void, Unit](println("start 1")) *> IO.sleep(1.second) *> IO.sync(println("release 1")))(_ => IO.unit[Void])
.bracket[ExitStatus](_ => IO.sync[Void, Unit](println("start 2")) *> IO.sleep(1.second) *> IO.sync(println("release 2")))(_ => IO.sync(ExitStatus.ExitNow(0)))
.fork.flatMap(f => f.interrupt(new RuntimeException("cancel")) *> IO.never)
Output:
start 1
start 1
java.lang.Error: Defect: Fiber is not in executing or async state
at scalaz.ioeffect.RTS$FiberContext.enterAsyncStart(RTS.scala:931)
at scalaz.ioeffect.RTS$FiberContext.evaluate(RTS.scala:514)
at scalaz.ioeffect.RTS$FiberContext.$anonfun$fork$1(RTS.scala:761)
at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:12)
at scalaz.ioeffect.RTS$$anon$1.run(RTS.scala:117)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
release 1
And this behavior is what made me jump to conclusions.
Metadata
Metadata
Assignees
Labels
No labels