Skip to content

MaxTotal does not take idle resources into account #440

@Jasper-M

Description

@Jasper-M
scala> val p = IO.ref(0).flatMap(ref =>
     |   KeyPool.Builder((i: Int) => Resource.make(ref.update(_ + 1).as(i))(i => IO.println(s"kill $i") *> ref.update(_ - 1)))
     |     .withMaxTotal(5)
     |     .withMaxIdle(5)
     |     .build.use{ keypool =>
     |       keypool.take(0).replicateA(5).use(_ => ref.get.flatMap(i => IO.println(s"total $i"))) *>
     |       keypool.take(1).replicateA(5).use(_ => ref.get.flatMap(i => IO.println(s"total $i"))) *>
     |       IO.println("DONE") *>
     |       ref.get
     |     }
     | )
val p: cats.effect.IO[Int] = IO(...)

scala> p.unsafeRunSync()
total 5
total 10
kill 1
kill 1
kill 1
kill 1
DONE
kill 0
kill 0
kill 0
kill 0
kill 0
kill 1
val res29: Int = 6

As you can see, at one point 10 resources are allocated, while the max is set to 5. At the end there are still 6 which might be a separate issue...

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions