title: Java cloudera impala connection unstable: with [Simba][ImpalaJDBCDriver](500151) Error setting/closing session: {0}
body: <p>I wrote a very simple Java app to query the Hadoop table (which is mange by someone else), but the connection is unstable. I tried to use <a href="https://commons.apache.org/proper/commons-dbcp/api-1.2.2/org/apache/commons/dbcp/BasicDataSource.html" rel="nofollow noreferrer">BasicDataSource</a> to manage the connection, the same connection issue remains. Is this a Hadoop issue, or there is something I can do?</p>
  <p>Here are my code:</p>
  <pre><code>package com.example.demo;
  
  import org.apache.commons.dbcp.BasicDataSource;
  import org.springframework.stereotype.Service;
  
  
  @Service
  public class ImpalaConnection {
  
  
      private String impalaDriverName = &quot;com.cloudera.impala.jdbc4.Driver&quot;;
  
      private BasicDataSource bds = new BasicDataSource();
  
      public ImpalaConnection() {
          //Set database driver name
          bds.setDriverClassName(impalaDriverName);
          //Set database url
          String serverName = &quot;&quot;; // my impala url
          String serverPort = &quot;21050&quot;;
          String connectionUrl = &quot;jdbc:impala://&quot; + serverName + &quot;:&quot; + serverPort +&quot;;SocketTimeout=0;&quot; ;
          bds.setUrl(connectionUrl);
  //        //Set database user
  //        bds.setUsername(DB_USER);
  //        //Set database password
  //        bds.setPassword(DB_PASSWORD);
          //Set the connection pool size
  //        bds.setInitialSize(1);
          bds.setMinIdle(5);
          bds.setMaxIdle(10);
          bds.setValidationQueryTimeout(100); // in second
          
      }
  
      private static class DataSourceHolder {
          private static final ImpalaConnection INSTANCE = new ImpalaConnection();
      }
  
      public static ImpalaConnection getInstance() {
          return DataSourceHolder.INSTANCE;
      }
  
      public BasicDataSource getBds() {
          return bds;
      }
  
      public void setBds(BasicDataSource bds) {
          this.bds = bds;
      }
      
  }
  
  </code></pre>
  <pre><code>package com.example.demo;
  
  import org.apache.commons.dbcp.BasicDataSource;
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.boot.SpringApplication;
  import org.springframework.boot.autoconfigure.SpringBootApplication;
  
  import java.sql.*;
  
  @SpringBootApplication
  public class DemoApplication {
  
      @Autowired
      ImpalaConnection im;
  
      public static void main(String[] args) {
          SpringApplication.run(DemoApplication.class, args);
          for(int i = 1; i &lt;= 4; i++) {
              runQuery(i);
          }
  
      }
  
      public static void runQuery(int k) {
          System.out.println(k);
          try {
              BasicDataSource bds = ImpalaConnection.getInstance().getBds();
              Connection con = bds.getConnection();
              Statement statement = con.createStatement();
              ResultSet resultSet = statement.executeQuery(&quot;SELECT\n&quot; +
                      &quot;  msgs.messagepublishevent.convdetails.convid\n&quot; +
                      &quot;FROM \n&quot; +
                      &quot;dv_messagepublishevent_prq_local msgs,\n&quot; +
                      &quot;msgs.participants as participants\n&quot; +
                      &quot;WHERE msgs.year = 2020 \n&quot; +
                      &quot;LIMIT 10&quot;);
              ResultSetMetaData rsmd = resultSet.getMetaData();
              int columnsNumber = rsmd.getColumnCount();
              while (resultSet.next()) {
                  for (int i = 1; i &lt;= columnsNumber; i++) {
                      if (i &gt; 1) System.out.print(&quot;,  &quot;);
                      String columnValue = resultSet.getString(i);
                      System.out.print(columnValue + &quot; &quot; + rsmd.getColumnName(i));
                  }
                  System.out.println(&quot;&quot;);
              }
  
          } catch (Exception e) {
              e.printStackTrace();
          }
      }
  
  }
  
  </code></pre>
  <p>While I was able to connect to Hadoop from time to time, sometimes it's Error stack is produced:</p>
  <pre><code>java.sql.SQLException: [Simba][ImpalaJDBCDriver](500151) Error setting/closing session: {0}.
      at com.cloudera.hivecommon.api.HS2Client.openSession(Unknown Source)
      at com.cloudera.hivecommon.api.HS2Client.&lt;init&gt;(Unknown Source)
      at com.cloudera.hivecommon.api.HiveServer2ClientFactory.createClient(Unknown Source)
      at com.cloudera.hivecommon.core.HiveJDBCCommonConnection.connect(Unknown Source)
      at com.cloudera.impala.core.ImpalaJDBCConnection.connect(Unknown Source)
      at com.cloudera.jdbc.common.BaseConnectionFactory.doConnect(Unknown Source)
      at com.cloudera.jdbc.common.AbstractDriver.connect(Unknown Source)
      at org.apache.commons.dbcp.DriverConnectionFactory.createConnection(DriverConnectionFactory.java:38)
      at org.apache.commons.dbcp.PoolableConnectionFactory.makeObject(PoolableConnectionFactory.java:582)
      at org.apache.commons.pool.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:1188)
      at org.apache.commons.dbcp.PoolingDataSource.getConnection(PoolingDataSource.java:106)
      at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:1044)
      at com.example.demo.DemoApplication.runQuery(DemoApplication.java:28)
  Caused by: com.cloudera.support.exceptions.GeneralException: [Simba][ImpalaJDBCDriver](500151) Error setting/closing session: {0}.
      ... 13 more
  Caused by: org.apache.thrift.transport.TTransportException: java.net.SocketException: Connection reset
      at org.apache.thrift.transport.TIOStreamTransport.read(TIOStreamTransport.java:129)
      at org.apache.thrift.transport.TTransport.readAll(TTransport.java:86)
      at org.apache.thrift.protocol.TBinaryProtocol.readAll(TBinaryProtocol.java:429)
      at org.apache.thrift.protocol.TBinaryProtocol.readI32(TBinaryProtocol.java:318)
      at org.apache.thrift.protocol.TBinaryProtocol.readMessageBegin(TBinaryProtocol.java:219)
      at org.apache.thrift.TServiceClient.receiveBase(TServiceClient.java:69)
      at org.apache.hive.service.cli.thrift.TCLIService$Client.recv_OpenSession(TCLIService.java:159)
      at com.cloudera.hivecommon.api.HS2ClientWrapper.recv_OpenSession(Unknown Source)
      at org.apache.hive.service.cli.thrift.TCLIService$Client.OpenSession(TCLIService.java:146)
      at com.cloudera.hivecommon.api.HS2ClientWrapper.OpenSession(Unknown Source)
      at com.cloudera.hivecommon.api.HS2Client.openSession(Unknown Source)
      at com.cloudera.hivecommon.api.HS2Client.&lt;init&gt;(Unknown Source)
      at com.cloudera.hivecommon.api.HiveServer2ClientFactory.createClient(Unknown Source)
      at com.cloudera.hivecommon.core.HiveJDBCCommonConnection.connect(Unknown Source)
      at com.cloudera.impala.core.ImpalaJDBCConnection.connect(Unknown Source)
      at com.cloudera.jdbc.common.BaseConnectionFactory.doConnect(Unknown Source)
      at com.cloudera.jdbc.common.AbstractDriver.connect(Unknown Source)
      at org.apache.commons.dbcp.DriverConnectionFactory.createConnection(DriverConnectionFactory.java:38)
      at org.apache.commons.dbcp.PoolableConnectionFactory.makeObject(PoolableConnectionFactory.java:582)
      at org.apache.commons.pool.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:1188)
      at org.apache.commons.dbcp.PoolingDataSource.getConnection(PoolingDataSource.java:106)
      at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:1044)
      at com.example.demo.DemoApplication.runQuery(DemoApplication.java:28)
      at com.example.demo.DemoApplication.main(DemoApplication.java:19)
  Caused by: java.net.SocketException: Connection reset
      at java.net.SocketInputStream.read(SocketInputStream.java:210)
      at java.net.SocketInputStream.read(SocketInputStream.java:141)
      at java.io.BufferedInputStream.fill(BufferedInputStream.java:246)
      at java.io.BufferedInputStream.read1(BufferedInputStream.java:286)
      at java.io.BufferedInputStream.read(BufferedInputStream.java:345)
      at org.apache.thrift.transport.TIOStreamTransport.read(TIOStreamTransport.java:127)
      ... 23 more
  </code></pre>
  <p>Here is my dependencies</p>
  <pre><code>        &lt;dependency&gt;
              &lt;groupId&gt;com.cloudera.impala.jdbc&lt;/groupId&gt;
              &lt;artifactId&gt;ImpalaJDBC4&lt;/artifactId&gt;
              &lt;version&gt;2.5.36&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;com.cloudera.impala.jdbc&lt;/groupId&gt;
              &lt;artifactId&gt;TCLIServiceClient&lt;/artifactId&gt;
              &lt;version&gt;2.5.36&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.apache.hive&lt;/groupId&gt;
              &lt;artifactId&gt;hive-jdbc&lt;/artifactId&gt;
              &lt;version&gt;1.2.1&lt;/version&gt;
          &lt;/dependency&gt;
  </code></pre>