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#buffer doesn't preserve order of elements #8699
Comments
The issue is actually in import zio.*
object Test extends ZIOAppDefault {
val expected = Chunk.fromIterable(0 until 100)
def run =
(for {
queue <- Queue.bounded[Int](16)
_ <- queue.offerAll(expected).fork
actual <- queue.take.replicateZIO(100).map(Chunk.fromIterable)
orderPreserved = actual == expected
_ <- ZIO.when(!orderPreserved)(ZIO.fail(s"Order not preserved: $actual"))
} yield ()).forever
} |
Narrowed it down to this line:
When this is executed concurrently, you can end up inserting the element out of order. |
Actually me from 2018 knew that the queue implementation was not 100% fair 😆 #447 (comment) When it comes to streams though, I think we expect the order to be maintained? |
@ghostdogpr I'm currently attempting an optimization on
looking at
|
/bounty $150 |
💎 $150 bounty • ZIOSteps to solve:
Thank you for contributing to zio/zio! |
Reproducer:
It returns false after just a few iterations. If I remove
.buffer(16)
, it seems to work fine.The text was updated successfully, but these errors were encountered: