Skip to content

Destroy borrowed resources during cleanup - #293

Open
iRevive wants to merge 2 commits into
typelevel:mainfrom
iRevive:borrowed-resource-fix
Open

iRevive wants to merge 2 commits into
typelevel:mainfrom
iRevive:borrowed-resource-fix

Conversation

@iRevive

@iRevive iRevive commented Nov 10, 2021

Copy link
Copy Markdown
Contributor

My attempt to fix #291

}
}
case PoolOpen(_, borrowed, m2) =>
borrowed.toList.traverse { case (_, (_, destroy)) => destroy.attempt.void } >>

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice to invoke a user-specified callback in such an unusual scenario.

E.g.

class Builder[F[_]: Temporal, A, B] private[keypool] {
  ...
  def withOnBorrowedTermination(f: List[(A, F[Unit])] => F[Unit]): Builder
}

pm match {
case PoolClosed() => (0, Map.empty)
case PoolOpen(idleCount, m) =>
case PoolOpen(idleCount, _, m) =>

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically, a number of borrowed connections can be a part of the exposed state. It's a binary breaking change (if we talk about KeyPool#state), but this data can be made available via another method.

Moreover, if represent a borrowed resource as (B, F[Unit], FiniteDuration), leaking resources can be spotted.

@rossabaker
rossabaker self-requested a review November 14, 2021 02:02
@ChristopherDavenport

Copy link
Copy Markdown
Member

I've been working on something that takes this to a much further degree. The one major takeaway I've had is that you don't want this to be always true. It seems in line with the current implementation though. But this current implementation needs a lot more power to handle even more complex pooling scenarios.

@rossabaker

Copy link
Copy Markdown
Member

Well, this got lost in one of my GitHub bankruptcies, but I ran #291 and confirmed it's still an issue five years later.

@iRevive

iRevive commented Oct 6, 2026

Copy link
Copy Markdown
Contributor Author

I can resolve conflicts, but there may be a better solution to this issue.

@rossabaker rossabaker added this to the 0.4.12 milestone Oct 7, 2026
@iRevive
iRevive force-pushed the borrowed-resource-fix branch from f8d1542 to 0cedd16 Compare October 7, 2026 08:21
@iRevive
iRevive force-pushed the borrowed-resource-fix branch from 0cedd16 to fd88892 Compare October 7, 2026 16:00

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

A borrowed resource can postpone its termination

3 participants