HikariCP
HikariCP copied to clipboard
Check connection has not been closed at first while checking the validity of connection
In the current implementation of PoolBase#isConnectionDead(isConnectionAlive) setNetworkTimeout() is called firstly to check the connection validity: PoolBase#L151
In many JDBC drivers, calling Connection#setNetworkTimeout throws SqlException in the case when a connection is closed. For example, Postgres JDBC driver throws PSQLException("This connection has been closed.") by calling setNetworkTimeout() PgConnection#L1622 PgConnection.java#L883
The behavior of isConnectionDead() method looks odd because in the case of apriori closed connection it causes an exception and logging warning. If a connection is not valid by the result of Connection.isValid method the warning is not logged. The warning message could be confusing due to the indirect relation between maxLifeTime parameter and closed connections.
The proposal is to check that connection is closed before calling setNetworkTimeout thereby not causing the exception and logging the warning.
Codecov Report
Merging #1890 (e7ffb6a) into dev (ed2da5f) will decrease coverage by
0.52%
. The diff coverage is100.00%
.
@@ Coverage Diff @@
## dev #1890 +/- ##
============================================
- Coverage 70.75% 70.22% -0.53%
+ Complexity 575 574 -1
============================================
Files 26 26
Lines 2171 2173 +2
Branches 311 311
============================================
- Hits 1536 1526 -10
- Misses 484 497 +13
+ Partials 151 150 -1
Impacted Files | Coverage Δ | |
---|---|---|
src/main/java/com/zaxxer/hikari/pool/PoolBase.java | 68.36% <100.00%> (-3.80%) |
:arrow_down: |
...ain/java/com/zaxxer/hikari/util/ConcurrentBag.java | 74.46% <0.00%> (-1.07%) |
:arrow_down: |
Continue to review full report at Codecov.
Legend - Click here to learn more
Δ = absolute <relative> (impact)
,ø = not affected
,? = missing data
Powered by Codecov. Last update ed2da5f...e7ffb6a. Read the comment docs.
Brett has explained the reason why not to solve this problem in this way in an earlier comment here: https://github.com/brettwooldridge/HikariCP/issues/1212#issuecomment-417404421