Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is there a way to drop or close an actual connection when I'm using PooldConnection? #121

Open
atuk721 opened this issue Sep 23, 2021 · 4 comments

Comments

@atuk721
Copy link

atuk721 commented Sep 23, 2021

Because when I work with the connection of PooldConnection got by Pool.get and face some error that a protocol of the connection became bad state, I'd liket to close the actual connection.

I don't want to use test_on_checkout because it's high impact for performance.

@bkontur
Copy link

bkontur commented Sep 23, 2021

I had similar issue, I hacked it like this:

implement has_broken with boolean holder

fn has_broken(&self, conn: &mut MyConnection) -> bool {
    if self.release_on_return_to_pool.get() {
            return true;
    }
...
pub struct MyConnection {
...
    /// Indicates that we want to release this connection on return to pool (used for gracefull shutdown)
    release_on_return_to_pool: Cell<bool>,
...
impl ProtocolRunnerConnection {
...
    /// Mark connection as "destroy" when return back to pool
    pub fn set_release_on_return_to_pool(&self) {
        self.release_on_return_to_pool.set(true);
    }
...
}

so when I have aquired connection and some error occures, I can decide, if to return connection to pool or to destroy it by calling set_release_on_return_to_pool

@bkontur
Copy link

bkontur commented Sep 23, 2021

@sfackler
if this solution is ok, I could maybe do pull request to your library,
btw. r2d2 is very cool and works perfectly for me

@thomasmost
Copy link

This seems like quite the hack. Is there really no way of closing or returning a connection to the pool explicitly?

I'd expect something like
connection.close() for example— or pool.reclaim(connection)

@thomasmost
Copy link

FWIW I found one source that says connections are returned to the pool as soon as they go out of scope

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

No branches or pull requests

3 participants