typelevel / typelevel/fs2

Inserting a map stops propagation of IOLocal

Open
#3,103 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Scala
Stars
2.5k
Forks
636
Avg merge
2d 4h
Merged PRs (30d)
7

Description

Originally reported by @kamilkloch , I've done some minimisation. Reproduced in fs2 3.4.0, it seemed to work correctly on 3.0.2 (which I happened to have at hand). @Jasper-M points to https://github.com/typelevel/fs2/pull/2572 as the probable change.

def no =
    IOLocal(false).flatMap { local =>
      Stream
        .eval(local.set(true))
        .evalMap(_ => local.get)
        .map(x => x)
        .compile
        .toVector
    }
     .unsafeRunSync() // Vector(false)
     

  def yes =
    IOLocal(false).flatMap { local =>
      Stream
        .eval(local.set(true))
        .evalMap(_ => local.get)
        .compile
        .toVector
    }
     .unsafeRunSync() // Vector(true)

  def yes2 =
    IOLocal(false).flatMap { local =>
      Stream
        .eval(local.set(true) >> local.get)
        .compile
        .toVector
    }
     .unsafeRunSync() // Vector(true)

  def yes3 =
    IOLocal(false).flatMap { local =>
      (Stream.exec(local.set(true)) ++ Stream.eval(local.get))
        .compile
        .toVector
    }
     .unsafeRunSync() // Vector(true)

  def no2 =
    IOLocal(false).flatMap { local =>
      (Stream.exec(local.set(true)) ++ Stream.eval(local.get))
        .map(x => x)
        .compile
        .toVector
    }
     .unsafeRunSync() // Vector(false)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the minimal reproductions in the issue and compare the behavior change associated with typelevel/fs2 pull request 2572. Trace how adding map affects IOLocal propagation in the stream evaluation path, then verify that the no and no2 examples return true while the other examples retain their shown results.

Written by the indexing model from the issue text.

Assessment

Tech stack
scala
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.