Skip to content

Proposal: Drain connection pool #249

@sgoll

Description

@sgoll

Unless I am mistaken, there is currently no way to drain the connection pool "from the outside", i.e. shut down the pool—when dropping it, any remaining idle connections will stay around until they are reclaimed by the background reaper, but only when their idle time has come.

I propose to add a method drain() or shut_down() or something along these lines that does the following:

  • Immediately drop all idle connections (as if their idle timeout had been reached).
  • Adjust the internal pool configuration to not lend out any further connections.

My use case is primarily the coordinated shutdown of a database pool during tests: after a test has finished, I want to stop the pool without having to wait for idle timeouts to release all still-open connections—usually, I would just drop the pool and let the process terminate itself, but in my case, I am creating a separate test database for each test, and I can only drop that when no connection is using it anymore, i.e. I must close all connections before the drop can complete.

For now, my workaround is to set a very low idle timeout (500 ms) and reaper limit (100 ms). This way, I can get the idle time after each test down to 500 ± 100 ms, but bringing it down to essentially 0 would allow me to run more tests in the same time.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions