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

ZStream.groupedWithin works in unexpected way for infinite stream #8686

Open
DenisKusakin opened this issue Mar 11, 2024 · 8 comments
Open

Comments

@DenisKusakin
Copy link

DenisKusakin commented Mar 11, 2024

The behavior is only reproducible on ZIO v1.0.18, works as expected for elder versions

import zio.clock.Clock
import zio.duration.durationInt
import zio.stream.ZStream
import zio.{ExitCode, URIO}
object Main extends zio.App {

  override def run(args: List[String]): URIO[zio.ZEnv, ExitCode] = {
    ZStream
      .fromIterable(Seq(1, 2))
      .forever
      .mapAccum(Set[Int]())(
        (acc, i) =>
          if (acc.contains(i)) {
            (acc, None)
          } else {
            (acc + i, Some(i))
        }
      )
      .collectSome
      //The stream above generates only two elements
      // so after 5 seconds those two elements should be grouped
      .groupedWithin(3, 5.seconds)
      .take(1)
      .runCollect
      .map(_ => ExitCode.success)
      .provideCustomLayer(Clock.live)
  }
}

Expected result: Complete with exit code 0
Actual result: The program is never completed

@krsvital
Copy link

forever ???

@DenisKusakin
Copy link
Author

forever ???

Yes, the top-level stream is an infinite stream of 1, 2, 1, 2,..., then there is filtering that produces only two elements: 1, 2. I expect that groupedWithin will produce chunk [1, 2] in 5 seconds, take(1) will take this chunk and program completed

@jdegoes
Copy link
Member

jdegoes commented Apr 11, 2024

We will take a PR for ZIO 1.x issues, of course, but we will need a volunteer to fix this issue.

@jdegoes
Copy link
Member

jdegoes commented May 8, 2024

/bounty $50

Copy link

algora-pbc bot commented May 8, 2024

💎 $50 bounty • ZIO

Steps to solve:

  1. Start working: Comment /attempt #8686 with your implementation plan
  2. Submit work: Create a pull request including /claim #8686 in the PR body to claim the bounty
  3. Receive payment: 100% of the bounty is received 2-5 days post-reward. Make sure you are eligible for payouts

Thank you for contributing to zio/zio!

Add a bountyShare on socials

Attempt Started (GMT+0) Solution
🟡 @DenisKusakin May 11, 2024, 2:42:17 PM #8873

@DenisKusakin
Copy link
Author

DenisKusakin commented May 11, 2024

/attempt #8686
Looks like the issue is related with PR. I believe that by making concat faster it somehow introduced this behavior

Copy link

algora-pbc bot commented May 18, 2024

@DenisKusakin: Reminder that in 7 days the bounty will become up for grabs, so please submit a pull request before then 🙏

Copy link

algora-pbc bot commented May 18, 2024

💡 @DenisKusakin submitted a pull request that claims the bounty. You can visit your bounty board to reward.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants