I am using cloudera hive jdbc https://www.cloudera.com/downloads/connectors/hive/jdbc/2-6-2.html
Sometimes, when the calling of getConnection() fails (not always, depends on server stability), it shows this exception:
MyDAO - Cannot create connection from DataSource@21f421b8
at com.cloudera.hiveserver2.hivecommon.api.HS2Client.closeSession(Unknown Source)
at com.cloudera.hiveserver2.hivecommon.core.HiveJDBCCommonConnection.establishConnection(Unknown Source)
at com.cloudera.hiveserver2.jdbc.core.LoginTimeoutConnection.connect(Unknown Source)
at com.cloudera.hiveserver2.jdbc.common.BaseConnectionFactory.doConnect(Unknown Source)
at com.cloudera.hiveserver2.jdbc.common.AbstractDataSource.getSimbaConnection(Unknown Source)
at com.cloudera.hiveserver2.jdbc.common.AbstractDataSource.getConnection(Unknown Source)
And when I check with netstat cmd:
netstat -an --tcp --program
There's a new socket connection established, I have to wait about 1 hour then see that tcp connection gone.
The question is:
- Why when I call getConnection(), the closeSession() is called?
- Is it because the closeSession() fails, the tcp connection cannot be released? Is it considered as a connection leakage?
I decompiled the driver, check the H2SClient class:
If there is any exception which makes the line 8 cannot be reached, the socket connection is not closed. That closing should be called also in catch block or finally block: