-
Notifications
You must be signed in to change notification settings - Fork 155
Added ability to enforce max connection lifetime #398
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
Conversation
Driver keeps idle socket connections in a connection pool. These connections can get invalidated while resting idle in the pool. They can be killed by network equipment like load balancer, proxy or firewall. It is also safer to refresh connections once in a while so that database can renew corresponding resources. This commit adds `maxConnectionLifetime` setting and makes driver close too old connections. Checking and closing happens in an application thread that tries to acquire a connection. Feature can be used on it's own or in combination with `connectionLivenessCheckTimeout` to guarantee validity of acquired connections.
@@ -281,6 +284,12 @@ public void setResourcesHandler( SessionResourcesHandler resourcesHandler ) | |||
} | |||
|
|||
@Override | |||
public long creationTimestamp() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to expose creationTimestamp
and lastUsedTimestamp
if we have a isValid
method?
when obtaining a conn from the pool
do
{
conn = pool.dequeue()
} while(!conn.isValid()) // where we calculate timestamp
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think addition of PooledConnection#isValid()
will make connection too smart. It'll basically have to be aware of pool settings, do ping and stuff. I guess we could move this into existing ConnectionValidator
interface. Maybe as a separate PR?
return maxConnectionLifetime; | ||
} | ||
|
||
public boolean maxConnectionLifetimeConfigured() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be okay to assume -1 or negative indicate infinite
or forever
, rather than not configured.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, that's basically what it means in the code. Pool treats negative and zero as if connections have infinite lifetime. Do you think this method should reflect this in it's name?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changes look fine for me.
Driver keeps idle socket connections in a connection pool. These connections can get invalidated while resting idle in the pool. They can be killed by network equipment like load balancer, proxy or firewall. It is also safer to refresh connections once in a while so that database can renew corresponding resources.
This PR adds
maxConnectionLifetime
setting and makes driver close too old connections. Checking and closing happens in an application thread that tries to acquire a connection. Feature can be used on it's own or in combination withconnectionLivenessCheckTimeout
to guarantee validity of acquired connections.