Thanks to visit codestin.com
Credit goes to github.com

Skip to content

ZIO 2.0.1, FiberRuntime memory leak, vol. 3 #7235

@adwells-ds

Description

@adwells-ds

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

image

image

image

@adamgfraser Sorry to disturb you again, but I believe it is the last issue:)

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingstreamZIO Stream

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions