-
Notifications
You must be signed in to change notification settings - Fork 68
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix unlawful instances #616
Fix unlawful instances #616
Conversation
…ve typed errors in the same Cause as external interruptions, so previous definition was incorrect There remain test failures in 'canceled sequences onCancel in order' – they are occur when `genOfRace`/`genOfParallel` or `genCancel` occurs, so something might still be wrong with outcome conversion in these case OR there may be bugs in ZIO 2 (or some more tricky behavior)
# Conflicts: # zio-interop-cats-tests/shared/src/test/scala/zio/interop/CatsSpecBase.scala # zio-interop-cats/shared/src/main/scala/zio/interop/package.scala
Can we create a reproducer of the failing test case using just ZIO? |
I think it should look like this but both sides are hanging for me here: def canceled = {
def loopUntilInterrupted: UIO[Unit] =
ZIO.descriptorWith(d => if (d.interrupters.isEmpty) ZIO.yieldNow *> loopUntilInterrupted else ZIO.unit)
for {
_ <- ZIO.withFiberRuntime[Any, Nothing, Unit]((thisFiber, _) => thisFiber.interruptAsFork(thisFiber.id))
_ <- loopUntilInterrupted
} yield ()
}
ZIO.uninterruptibleMask(_ => canceled.onExit(_ => ZIO.never.unit)) <-> ZIO.uninterruptibleMask(_ => canceled).onExit(_ => ZIO.never.unit) |
@neko-kai I'm looking at this law and having a little trouble figuring out how it is supposed to work: F.uncancelable(_ => F.onCancel(fa, fin)) <-> F.onCancel(F.uncancelable(_ => fa), fin) Per "uncancelable eliminates onCancel" it appears that the However, in the right hand side What am I missing here? |
@adamgfraser
Avoiding 'gaps' here seems to mean that an uncancelable region should grant uncancelability to its outer error handlers as well - so avoiding getting interruption immediately after F.uncancelable ends. I don't know why ZIO1 passes this, on a glance I couldn't find anything that specifically enables this behavior. It seems like the problem is indeed that we're running
So LHS is interrupted, but RHS is hanging. We can only get interrupted if However, we also hang without
I'm not sure how critical is this law - or why ZIO1 passes it - but it's possible to ignore it by subclassing |
The funny thing is that I can reproduce it with |
@johnspade For this law both the RHS and the LHS should cancel, not hang. |
This cancelation stuff is way over my head :(
But |
@neko-kai I did see that comment. 😃 @johnspade I think these are the ones you want to test, which both are canceled: object Example extends IOApp {
val left =
IO.uncancelable(_ => IO.canceled.onCancel(IO.never))
val right =
IO.uncancelable(_ => IO.canceled).onCancel(IO.never)
def run(args: List[String]): IO[ExitCode] =
left *> IO(ExitCode.Success)
} However, I think this is basically because cancelation is only checked on object Example extends IOApp {
val left =
IO.uncancelable(_ => IO.canceled.onCancel(IO.never))
val right =
(IO.uncancelable(_ => IO.canceled) *> IO.unit).onCancel(IO.never)
def run(args: List[String]): IO[ExitCode] =
left *> IO(ExitCode.Success)
} This feels like it will be a difficult property to support precisely because it doesn't support equational reasoning and arguably relies on an implementation detail of interruption only being checked for between certain operations. It seems like at this point we do feel like these changes are correct as far as they go and make the tests more robust by testing more generated values. So perhaps we should disable this test, merge this PR, and open a new issue to explore how, if at all, this behavior can be supported? |
As I've said, I'm not sure how important this law is - but it doesn't seem that important or strong enough to me, so I think it's ok to disable the test and merge. |
Okay, cool, I'll create an issue and disable the test |
@johnspade Thank you for your work on this! 🙏 |
Thank you for your help @adamgfraser & @neko-kai! |
Continue pushing #595