question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Duplicated fibers in fiber dump

See original GitHub issue

Running the following code:

package io.github.timwspence.cats.stm

import cats.effect._

object Test extends IOApp.Simple {
  override def run: IO[Unit] =
    for {
      d <- IO.deferred[Int]
      f <- d.get.start
      _ <- f.join
      _ <- d.complete(1)
    } yield ()
}

on JDK 17 and pressing Crtl-T for a fiber dump yields the following:

cats.effect.IOFiber@707af0cd WAITING

cats.effect.IOFiber@539c7a54 WAITING
 ├ main @ jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 ├ main @ jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 ├ main @ jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 ╰ main @ jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

cats.effect.IOFiber@539c7a54 ACTIVE
 ├ main @ jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 ├ main @ jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 ├ main @ jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 ╰ main @ jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

Thread[io-compute-5,5,run-main-group-1] (#5): 0 enqueued
Thread[io-compute-11,5,run-main-group-1] (#11): 0 enqueued
Thread[io-compute-2,5,run-main-group-1] (#2): 0 enqueued
Thread[io-compute-4,5,run-main-group-1] (#4): 0 enqueued
Thread[io-compute-9,5,run-main-group-1] (#9): 0 enqueued
Thread[io-compute-1,5,run-main-group-1] (#1): 0 enqueued
Thread[io-compute-6,5,run-main-group-1] (#6): 0 enqueued
Thread[io-compute-3,5,run-main-group-1] (#3): 0 enqueued
Thread[io-compute-7,5,run-main-group-1] (#7): 0 enqueued
Thread[io-compute-0,5,run-main-group-1] (#0): 0 enqueued
Thread[io-compute-8,5,run-main-group-1] (#8): 0 enqueued
Thread[io-compute-10,5,run-main-group-1] (#10): 0 enqueued

Global: enqueued 0, foreign 1, waiting 2

Note that fiber 539c7a54 is duplicated as both active and waiting. I’ve re-run it a bunch of times and the output appears to be deterministic

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:9 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
armanbilgecommented, Nov 29, 2021

So we do have a situation of the same fiber being shown twice, because it is indeed registered with two different keys.

Yes, this is a general problem. I’m pretty sure that evalOning a fiber which then suspends will lead to the exact same outcome, since it will be registered with both the async callback and the opaque object used for evalOn registration.

What does the IOApp registration aim to achieve exactly?

See https://github.com/typelevel/cats-effect/pull/2587#discussion_r757802618:

By explicitly monitoring the main fiber, we are guaranteed that it appears in the fiber dump even if a foreign runtime is being used.

0reactions
TimWSpencecommented, Nov 29, 2021

Confirmed with

package io.timwspence

import cats.effect._
import scala.concurrent.ExecutionContext
import java.util.concurrent.Executors

object Test extends IOApp.Simple {
  val ec = ExecutionContext.fromExecutorService(Executors.newSingleThreadExecutor())
  override def run: IO[Unit] =
    for {
      d <- IO.deferred[Int]
      f <- d.get.evalOn(ec).start
      _ <- f.join
      _ <- d.complete(1)
    } yield ()
}

that evalOn introduces the same problem and that the same fix works! 🎉

Read more comments on GitHub >

github_iconTop Results From Across the Web

Allow Fiber.dump to dump all fibers (even from other ... - GitHub
Today (1.0-RC17), Fiber.dump does not print fiber dumps for fibers started from an other unsafeRun. This is extremely problematic in app ...
Read more >
Fibers, Oh My!
This idea of fibers yielding to each other is what is known as cooperative scheduling. Fibers effectively move the idea of context switching ......
Read more >
Rhabdomyolysis: MedlinePlus Medical Encyclopedia
Rhabdomyolysis is the breakdown of muscle tissue that leads to the release of muscle fiber contents into the blood.
Read more >
Fiber Identification Student Guide
BACKGROUND INFORMATION In the world of forensics the identification of a fiber or piece of fabric can provide valuable information for law enforcement ......
Read more >
Fiber Dumps · Cats Effect - Typelevel
A fiber dump prints every fiber known to the runtime, regardless of whether they are suspended, blocked, yielding, active on some foreign runtime...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found