Skip to content
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

Weird interaction between cancelation and interruptWhen #2962

Merged
merged 6 commits into from
Aug 12, 2022

Conversation

TimWSpence
Copy link
Member

@TimWSpence TimWSpence commented Aug 11, 2022

Fix hanging when combining Stream.eval(F.canceled) and interruptWhen.

I believe that the .as(canceledError) is safe as our fa.attempt was canceled which means that cancelation is unmasked in this scope and hence F.canceled.as(canceledError) <-> F.canceled. This matches the behaviour in Scope#interruptibleEval when there is no interrupt context and it binds fa.attempt directly.

Weird interaction between cancelation and interruptWhen
@TimWSpence TimWSpence changed the title Failing test Weird interaction between cancelation and interruptWhen Aug 11, 2022
I believe that the `.as(canceledError)` is safe as our `fa.attempt` was
canceled which means that cancelation is unmasked in this scope and
hence `F.canceled.as(canceledError) <-> F.canceled`. This matches the
behaviour in `Scope#interruptibleEval` when there is no interrupt
context and it binds `fa.attempt` directly
@TimWSpence TimWSpence marked this pull request as ready for review August 11, 2022 16:47
deferred.get should not error or be canceled
Copy link
Member

@armanbilge armanbilge left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice find+fix!

case Left(other) => Left(other)
F.raceOutcome(deferred.get, fa.attempt).flatMap {
case Right(oc) =>
oc.embed(F.canceled.as(canceledError)).map(_.leftMap(Outcome.Errored(_)))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a nit, maybe we can write this with oc.fold(...) to save the two separate ops?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yep, good call 👍 Will fix tomorrow

@mpilquist mpilquist merged commit 7d582bc into typelevel:main Aug 12, 2022
@armanbilge armanbilge linked an issue Aug 12, 2022 that may be closed by this pull request
@TimWSpence TimWSpence deleted the cancelation-and-interrupt-when branch August 12, 2022 13:04
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.

Weird interaction between cancelation and interrruptWhen
3 participants