Skip to content

WriterT[IO.. losing logs in parEvalMap hints at problem with Concurrent instance for WriterT ? #3764

Description

@benhutchison

I'm seeing FS2's parEvalMap dropping logs emitted by WriterT[IO.., while the sequential cousin evalMap retains them, as does a "desugared" Writer using parEvalMap.

Since parEvalMap is written in terms of Concurrent this hints at a potential problem in the WriterT instance, although I was not able to spot a problem from a visual inspection.

import fs2.*
import cats.*
import cats.syntax.all.*
import cats.data.*
import cats.effect.*
import cats.effect.implicits.*

object ConcurrentWriterTTest extends IOApp.Simple:
  def tell(s: String): WriterT[IO, Chain[String], Unit] = WriterT.tell(Chain(s))

  val run = Stream(1)
    .parEvalMap(Int.MaxValue): _ =>
      tell("loglog")

    .compile.drain.written.flatMap(IO.println) //output: Chain()

object SequentialWriterTTest extends IOApp.Simple:
  def tell(s: String): WriterT[IO, Chain[String], Unit] = WriterT.tell(Chain(s))

  val run = Stream(1)
    .evalMap: _ =>
      tell("loglog")

    .compile.drain.written.flatMap(IO.println) //output: Chain(loglog)

object ConcurrentWriterDesugaredTest extends IOApp.Simple:
  def tell(s: String): IO[(Unit, Chain[String])] = IO.pure(() -> Chain(s))

  val run = Stream(1)
    .parEvalMap(Int.MaxValue): _ =>
      tell("loglog")

    .compile.toList.map(_.map(_._2)).flatMap(IO.println) //output: List(Chain(loglog))

Cats Effect 3.5.1 and FS2 3.7.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions