Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@adamgfraser
Copy link
Contributor

This test raises the issue of how timeout should behave in an uninterruptible region. The current behavior is if the program is externally interrupted the timeout fiber will be interrupted because interruption is propagated from parent to child and the timeout fiber is interruptible. This means the timeout fiber "wins" the race by terminating first and causes the timeout to fail with an interrupted cause, which seems clearly incorrect.

I think the correct behavior is that the timeout should get the full time to execute and essentially should behave as if no external interruption had occurred since it is in an uninterruptible region. To achieve this we fork the timeout fiber in the global scope instead of the parent scope so the only way it will be interrupted is if the workflow being timed out terminates and interrupts it.

test("timeout does not allow interruption to be observed in uninterruptible region") {
  ZIO.uninterruptible {
    for {
      promise <- Promise.make[Nothing, Unit]
      fiber   <- (promise.succeed(()) *> ZIO.sleep(2.second).timeout(1.seconds)).fork
      _       <- promise.await
      exit    <- fiber.interrupt
    } yield assert(exit)(not(isInterrupted))
  }
} @@ TestAspect.withLiveClock

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants