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

inherit FiberRef's when a failed fiber joins #8731

Open
wants to merge 1 commit into
base: series/2.x
Choose a base branch
from

Conversation

vagroz
Copy link
Contributor

@vagroz vagroz commented Apr 9, 2024

I faced with a problem similar to #8721

Fiber#join doesn't inherit FiberRef values if the fiber was failed.

For example:

val ref: FiberRef[Set[String]] =
    Unsafe.unsafe(implicit unsafe => FiberRef.unsafe.make[Set[String]](Set.empty, join = _ ++ _))

  def request(system: String, fail: Boolean): Task[Unit] = for {
    _ <- ref.update(_ + system)
    _ <- ZIO.fail(new IllegalStateException("Booom!")).when(fail)
  } yield ()

  override val run =
    for {
      f    <- request("foo", fail = true).fork
      _    <- request("bar", fail = false)
      _ <- f.join.ignore
      data <- ref.get
      _    <- Console.printLine(s"Completed: $data")
    } yield ()

prints just bar, but

 for {
      _    <- request("foo", fail = true).ignore
      _    <- request("bar", fail = false)
      data <- ref.get
      _    <- Console.printLine(s"Completed: $data")
    } yield ()

prints foo, bar.

I expected these snippets to work the same way.
The same expectation is about ZIO#disconnected:

_ <- request("disconnected", fail = true).disconnect.ignore

Now this discards FiberRef updates bacause uses .join under the hood.

If this behavior must be corrected, I will be glad if my PR is approved

@vagroz vagroz force-pushed the fix_fiber_join branch 3 times, most recently from 4564c65 to d8d6a48 Compare April 10, 2024 12:30
@vagroz vagroz changed the title fix FiberRef inheritance when a fiber joins inherit FiberRef's when a failed fiber joins Apr 10, 2024
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.

None yet

1 participant