Skip to content

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

Merged
merged 1 commit into from
Aug 14, 2017

Conversation

lutovich
Copy link
Contributor

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 with connectionLivenessCheckTimeout to guarantee validity of acquired connections.

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.
@lutovich lutovich requested review from zhenlineo and ali-ince August 10, 2017 15:02
@@ -281,6 +284,12 @@ public void setResourcesHandler( SessionResourcesHandler resourcesHandler )
}

@Override
public long creationTimestamp()
Copy link
Contributor

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

Copy link
Contributor Author

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()
Copy link
Contributor

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.

Copy link
Contributor Author

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?

Copy link
Contributor

@ali-ince ali-ince left a 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.

@zhenlineo zhenlineo merged commit af0f355 into neo4j:1.5 Aug 14, 2017
@lutovich lutovich deleted the 1.5-maxConnectionLifetime branch August 21, 2017 08:12
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

Successfully merging this pull request may close these issues.

3 participants