Skip to content

Commit

Permalink
Initial code to test connections before handing them out
Browse files Browse the repository at this point in the history
The goal is to fix issues where we have dead connections in the pool
which are being handed out. In particular, when all the connections in
the pool are dead it can easily exhaust a client's retry budget.x
  • Loading branch information
non committed Aug 14, 2024
1 parent cd0c148 commit 2e1b138
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions modules/core/shared/src/main/scala/util/Pool.scala
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,19 @@ object Pool {
case _ => ref.update { case (os, ds) => (os :+ None, ds) }
}

def createAlloc: F[(A, F[Unit])] = Concurrent[F].onError(rsrc(Tracer[F]).allocated)(restore)

// Here we go. The cases are a full slot (done), an empty slot (alloc), and no slots at
// all (defer and wait).
ref.modify {
case (Some(a) :: os, ds) => ((os, ds), a.pure[F])
case (None :: os, ds) => ((os, ds), Concurrent[F].onError(rsrc(Tracer[F]).allocated)(restore))
case (Nil, ds) =>
case (Some(a) :: os, ds) =>
((os, ds), recycler(a._1).attempt.flatMap {
case Right(true) => a.pure[F]
case Left(_) | Right(false) => dispose(a) *> createAlloc
})
case (None :: os, ds) =>
((os, ds), createAlloc)
case (Nil, ds) =>
val cancel = ref.flatModify { // try to remove our deferred
case (os, ds) =>
val canRemove = ds.contains(d)
Expand Down

0 comments on commit 2e1b138

Please sign in to comment.