poolex icon indicating copy to clipboard operation
poolex copied to clipboard

Manual checkouts and checkins of resources

Open hauleth opened this issue 6 months ago • 6 comments

Current implementation do not provide manual control over checkins and checkouts of the resources, which could be helpful in some situations where resource is checked out for longer periods (for example process lifetime).

hauleth avatar Jun 15 '25 20:06 hauleth

Hi 👋🏻

Please provide an example of where it might be needed. Now, in my opinion, you can use run in every case instead of checkout / checkin.

general-CbIC avatar Jun 16 '25 07:06 general-CbIC

Unfortunately, I cannot. The thing is that I am working on DB pooler similar to the pgBouncer. There I am checking out the DB connection for a duration of TCP connection, which mean that I am checking out a connection at the start of the connection and I keep it open for the whole lifetime of the process. There is no single function call that I can wrap in run nor I cannot wrap each query independently, because I need to reuse the same connection for the duration of the whole connection (and that connection must be checked out for sole use of this process).

There are other use cases that I can think of, but in general - long checkouts that are happening in GenServer or gen_statem processes are the situation where "manual checkouts" are must-have.

hauleth avatar Jun 16 '25 09:06 hauleth

Thank you very much for this example! I need some time to think about it.

general-CbIC avatar Jun 16 '25 09:06 general-CbIC

In other words, if we don't speak about implementation with "checkin" and "checkout", you need to have a guarantee that the current process will take the same worker from the pool, right?

general-CbIC avatar Jun 16 '25 10:06 general-CbIC

Yes, but at the same time I need to ensure that no one else will checkout that process in the meantime. Which in the end means exactly the same thing as manual checkouts.

hauleth avatar Jun 16 '25 10:06 hauleth

Okay, I understood 👍

general-CbIC avatar Jun 16 '25 10:06 general-CbIC