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

Fix Potential Nontermination When Layer Fails With Error #3994

Merged
merged 3 commits into from Jul 22, 2020

Conversation

adamgfraser
Copy link
Contributor

Resolves #3956.

The issue is that if the scope is already closed in ZIO#foreachPar_ the forked effects will never run and will never complete the promise, resulting in non-termination.

Also restores the changes to remove the by name parameters from ZLayer to address early initialization issues.

Note that this PR is not binary compatible.

@@ -2858,8 +2858,8 @@ object ZIO extends ZIOCompanionPlatformSpecific {
.forkManaged
_ <- interrupter.use_ {
ZIO
.whenM(result.await.map(!_)) {
causes.get.flatMap(ZIO.halt(_))
.whenM(ZIO.foreach(fibers)(_.await).map(_.exists(!_.succeeded))) {
Copy link
Member

Choose a reason for hiding this comment

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

Nothing is awaiting the result with this change. Is it still required?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're right. Deleted the old result and renamed failureTrigger to result.

Copy link
Member

@iravid iravid left a comment

Choose a reason for hiding this comment

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

Looks great. It'd be great to maintain the inversion of control where the child fibers are responsible for signalling the parent fiber that the overall task is completed, because that saves an O(n) of fiber awaits, but we can improve that in a follow up.

@adamgfraser
Copy link
Contributor Author

Yes. I think that may require additional combinators because child fibers may never run at all if the scope is already closed so they may not be able to signal that the task is completed.

@iravid
Copy link
Member

iravid commented Jul 22, 2020

Makes sense!

@adamgfraser adamgfraser merged commit 7d733c2 into zio:master Jul 22, 2020
@adamgfraser adamgfraser deleted the zlayer branch July 22, 2020 14:29
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.

Program stuck when Layer return error
2 participants