Close connections marked as evicted instead of returning them to the pool #2157
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
According to the documentation, connections that were in use during a soft eviction, are effectively evicted when returned to the pool. See Javadoc of
com.zaxxer.hikari.HikariPoolMXBean.softEvictConnections
That's not how it's currently implemented though. Connections that are marked as evicted are being closed when the connection is tried to be borrowed from the pool.
With this PR, connections marked as evicted are additionally closed when returned to the pool.
Because of race conditions, it's still possible that connections that are marked as evicted are being returned to the pool.
Therefore, I left the logic in
com.zaxxer.hikari.pool.HikariPool.getConnection(long)
as is.Why?
We use a database cluster in an active/passive setup. The JDBC connection string ensures that connections are always established with the active node.
On database maintenance we are able to switch the roles of the nodes. We then want to evict all current connections (connected to the now passive node) to ensure that new connections are established with the now active node.
With low volume of SQL executions it can take some time until a connection marked as evicted is being borrowed from the pool.
We would therefore have to adjust the minimumIdleTime to ensure that connections are being re-established in a timely manner.