hivejdbc-getconnection失败时的连接泄漏

nkcskrwz  于 2021-06-24  发布在  Hive
关注(0)|答案(1)|浏览(398)

我正在使用cloudera hive jdbchttps://www.cloudera.com/downloads/connectors/hive/jdbc/2-6-2.html
有时,当调用getconnection()失败时(并不总是,取决于服务器的稳定性),会显示以下异常:

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)

当我检查netstat cmd时:

netstat -an --tcp --program

有一个新的套接字连接建立,我必须等待约1小时,然后看到tcp连接消失。
问题是:
为什么在调用getconnection()时,会调用closesession()?
是因为closesession()失败,tcp连接无法释放吗?是否视为连接泄漏?

jtjikinw

jtjikinw1#

我反编译了驱动程序,检查h2sclient类:

public void closeSession() throws ErrorException {
    if (this.m_hasOpenSession) {
        try {
            TCloseSessionReq var1 = new TCloseSessionReq();
            var1.setSessionHandle(this.m_openSessionResp.getSessionHandle());
            this.m_client.CloseSession(var1);
            if (null != this.m_client && null != this.m_client.getInputProtocol() && null != this.m_client.getInputProtocol().getTransport()) {
                this.m_client.getInputProtocol().getTransport().close(); //line 8
            }

            this.m_hasOpenSession = false;
        } catch (Exception var3) {
            ErrorException var2 = HiveJDBCCommonDriver.s_HiveMessages.createGeneralException(HiveJDBCMessageKey.CONN_SESSION_ERR.name(), "Close Session Error");
            var2.initCause(var3);
            throw var2;
        }
    }

}

如果有任何异常导致无法到达第8行,则套接字连接未关闭。在catch block或finally block中也应调用该closing:

public void closeSession() throws ErrorException {
    if (this.m_hasOpenSession) {
        try {
            TCloseSessionReq var1 = new TCloseSessionReq();
            var1.setSessionHandle(this.m_openSessionResp.getSessionHandle());
            this.m_client.CloseSession(var1);

            var2.initCause(var3);
            throw var2;
        } finally {
            if (null != this.m_client && null != this.m_client.getInputProtocol() && null != this.m_client.getInputProtocol().getTransport()) {
                this.m_client.getInputProtocol().getTransport().close(); //line 8
            }   
        }
    }
}

相关问题