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

Skip to content

Conversation

@adamgfraser
Copy link
Contributor

Resolves #4136.

We had actually resolved this issue previously in #1949 but removed it when we stopped logging pure interruptions, which inadvertently caused a regression because fiber failures other than interruption can subsequently be handled at a higher level of the application.

The basic problem here is that a fiber doesn't know who will join it or what they will do once joining it, so a fiber has to either report the error or not. Thus, when we fork a fiber if we intend to handle its errors ourselves we need to signal to the fiber that it does not need to log fiber failures. We can do this with calling run on the effect we are forking and then using flatMap(IO.done(_)) to flatten the exit value back into an effect. The implementation in raceWith is slightly more complicated now that it has been moved into FiberContext but conceptually the same.

I explored an alternative solution where we pushed more of this logic into FiberContext and each FiberContext had an error handler that could be overridden that we could explore if we wanted.

@adamgfraser adamgfraser requested a review from jdegoes August 29, 2020 14:37

val left = fork[EL, A](race.left.asInstanceOf[IO[EL, A]], race.scope)
val right = fork[ER, B](race.right.asInstanceOf[IO[ER, B]], race.scope)
val left = fork(race.left.asInstanceOf[IO[EL, A]].traced.run.untraced, race.scope)
Copy link
Member

Choose a reason for hiding this comment

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

This will add a lot of performance overhead to such a low level operation. Any way to cheat?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The tracing or the running? The tracing probably yes. The running will I think require some changes in FiberContext but I think they can be relatively straightforward.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Take a look at this version. Should be more efficient.

val value: ZIO[R, E, A],
val scope: Option[ZScope[Exit[Any, Any]]]
val scope: Option[ZScope[Exit[Any, Any]]],
val reportFailure: Option[Cause[Any] => Unit]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Adding an additional field here is a binary incompatible change even though this is package private. We could potentially revert and use the previous implementation of forkInternal for everything except the raceWith implementation.

Copy link
Member

Choose a reason for hiding this comment

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

Safe to mark as an exclusion I think

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think so too. Will do.

@adamgfraser adamgfraser requested a review from jdegoes September 1, 2020 16:44
val left = fork[EL, A](race.left.asInstanceOf[IO[EL, A]], race.scope)
val right = fork[ER, B](race.right.asInstanceOf[IO[ER, B]], race.scope)
val left = fork[EL, A](race.left.asInstanceOf[IO[EL, A]], race.scope, Some(_ => ()))
val right = fork[ER, B](race.right.asInstanceOf[IO[ER, B]], race.scope, Some(_ => ()))
Copy link
Member

Choose a reason for hiding this comment

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

Factor out Some(_ => ()) into a constant of FiberContext companion object.

@jdegoes jdegoes merged commit 8ae51bd into zio:master Sep 1, 2020
@adamgfraser adamgfraser deleted the forkinternal branch September 1, 2020 19:26
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.

zipPar fiber failures not handled correctly

3 participants