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

Support for recycling connections / setting a maximum age on connections #91

Closed
Roguelazer opened this issue Nov 16, 2016 · 6 comments
Closed

Comments

@Roguelazer
Copy link

It would be nice to be able to set a maximum lifetime for a connection and have it automatically destroyed on checkin once it exceeds that lifetime, so that we can forcibly recycle connections. The most pressing use-case for this is when the resource being connected to is behind a layer 4 (tcp) load balancer and you want to ensure that connections will pick up new hosts periodically. Most other connection pooling libraries that I've used have this functionality, and it seems self-evidently valuable to me.

This would require some fairly invasive changes (e.g., maintaining metadata about each connection at creation time so that we know how old it is), so I figured I'd run the concept by you before writing up a patch.

@mperham
Copy link
Owner

mperham commented Nov 16, 2016

The readme says connections must be self-healing and I have no plans to change that.

@Roguelazer
Copy link
Author

I'm not asking for healing support, I'm asking for pre-emptive closing support, which is not provided by any of the libraries that you cite as "self-healing" in the readme. If you're really uninterested in such functionality, I'll just fork, but I figured I'd ask first.

@mperham
Copy link
Owner

mperham commented Nov 16, 2016

I don't know of anyone else asking for that functionality so I think forking is the right thing to do here.

On Nov 16, 2016, at 10:31, James Brown notifications@github.com wrote:

I'm not asking for healing support, I'm asking for pre-emptive closing support, which is not provided by any of the libraries that you cite as "self-healing" in the readme. If you're really uninterested in such functionality, I'll just fork, but I figured I'd ask first.


You are receiving this because you commented.
Reply to this email directly, view it on GitHub, or mute the thread.

@ce07c3
Copy link

ce07c3 commented Dec 12, 2016

@Roguelazer would this aid in recycling keep-alive connections? I have a host I need to connect to quickly, so ideally the connections don't live for longer than a few seconds and are then recycled unless used in the meantime. Saves roughly 200 milliseconds per request compared to re-doing the SSL handshake.

@daveroberts
Copy link

@mperham I'm running into this issue as well.

    def connection
      return Mysql2::Client.new(options)
    end

    def pool
      @db ||= ConnectionPool.new(size: 5, timeout: 5){ connection }
    end

    def get_users
      pool.with do |db|
        return db.query("SELECT * from users")
      end
    end

the db.query line is throwing the exception. How can I tell connection_pool "this connection is dead, throw it away and grab another one" with the existing code?

@mperham
Copy link
Owner

mperham commented Aug 28, 2017

@daveroberts You cannot. From the readme:

There is no provision for repairing or checking the health of a connection; connections should be self-repairing.

@mperham mperham closed this as completed Aug 28, 2017
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

4 participants