-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Closed
Labels
Description
Apparently.. #7233 solves only the primitive case, but when FiberRuntime has cross-reference on each other(?) and already succeeded it will not be removed from the _children queue(?) and will keep all related resources (this is exact zio/zio-kafka#485 case)
How to reproduce(I tried to simplified it, but it is the smallest example I was able to come up with)
We have 2 independent streams, one is requesting records from another, the second fulfilling the requests:
import zio.*
import java.util.concurrent.atomic.AtomicLong
import zio.stream.*
object Main extends ZIOAppDefault:
case class Record(i: Int)
case class Request(cont: Promise[Option[Throwable], Chunk[Record]])
case class ConsumerLocal(
queue: Queue[Request]
):
// Fulfill promises
def runloop() = ZStream
.fromQueue(queue)
.mapZIO(_.cont.succeed(Chunk.fromIterable(0.to(100).map(Record(_)))))
.runDrain
.forkScoped
// Request new records
def makeStream() =
for {
p <- Promise.make[Throwable, Unit]
s = ZStream
.repeatZIOChunkOption(for {
request <- Promise.make[Option[Throwable], Chunk[Record]]
_ <- queue.offer(Request(request)).unit
result <- request.await
} yield result)
.interruptWhen(p)
} yield (p, s)
def stream() = ZStream.fromZIO(makeStream())
override def run =
val io = for {
q <- Queue.unbounded[Request]
c = ConsumerLocal(q)
_ <- c.runloop()
_ <- c.stream()
.mapZIOParUnordered(4) { case (_, b) =>
b.groupedWithin(100, 1.millis)
.mapZIO { rr =>
ZIO.attempt(rr)
}
.runDrain
}
.runDrain
} yield ()
io.exitCode
@adamgfraser Sorry to disturb you again, but I believe it is the last issue:)
erikvanoostenguizmaii, erikvanoosten and dario6695