java.lang.Exception: Apparent connection leak detected I already checked and made sure all my sql codes has a call to close method. Here's my HikariConfig : private HikariConfig hikariConfig() { HikariConfig config = new HikariConfig(); config.setDriverClassName(CLASS_FOR_NAME); config.setJdbcUrl(HOST); config.setUsername(USER); config.setPassword(PASS); config.addDataSourceProperty("cachePrepStmts", "true"); config.addDataSourceProperty("prepStmtCacheSize", "250"); config.addDataSourceProperty("prepStmtCacheSqlLimit", "2048"); config.setLeakDetectionThreshold(TimeUnit.SECONDS.toMillis(30)); config.setValidationTimeout(TimeUnit.MINUTES.toMillis(1)); config.setMaximumPoolSize(40); config.setMinimumIdle(0); config.setMaxLifetime(TimeUnit.MINUTES.toMillis(2)); // 120 seconds max life time config.setIdleTimeout(TimeUnit.MINUTES.toMillis(1)); // minutes config.setConnectionTimeout(TimeUnit.MINUTES.toMillis(5)); // millis config.setConnectionTestQuery("/* ping */ SELECT 1"); return config; } here's how my queries look like : public ArrayList<LocationType> getLocationTypes() { ArrayList<LocationType> locationTypes = new ArrayList<>(); Connection connection = null; PreparedStatement pstmt = null; ResultSet resultSet = null; try { connection = DataSource.getInstance().getConnection(); pstmt = connection.prepareStatement("SELECT\n" + " location_type_id,\n" + " location_type_name\n" + "FROM tablename;"); resultSet = pstmt.executeQuery(); while (resultSet.next()) { locationTypes.add(new LocationType(resultSet.getInt("location_type_id"), resultSet.getString("location_type_name"))); } } catch (Exception e) { e.printStackTrace(); } finally { if (resultSet != null) try { resultSet.close(); } catch (SQLException e) { } if (pstmt != null) try { pstmt.close(); } catch (SQLException e) { } if (connection != null) try { connection.close(); } catch (SQLException e) { } } return locationTypes; } I've already tried increasing the connectionLeakDetection, max connection and minimum idle but none of that solved the issue. I have read that it could be caused by the machine(low resources) and connections being closed, I think however, none of these causes the issue. I noticed that some long queries in my code are now being detected as connection leak, even though I am not calling their methods. I hope you guys could help. This is the stack trace : at com..database.DataSource.getConnection(DataSource.java:148)

Stack Overflow | JRojo | 2 months ago
  1. 0

    HikariCP detects connectionleak even though all of my code has a call to close method

    Stack Overflow | 2 months ago | JRojo
    java.lang.Exception: Apparent connection leak detected I already checked and made sure all my sql codes has a call to close method. Here's my HikariConfig : private HikariConfig hikariConfig() { HikariConfig config = new HikariConfig(); config.setDriverClassName(CLASS_FOR_NAME); config.setJdbcUrl(HOST); config.setUsername(USER); config.setPassword(PASS); config.addDataSourceProperty("cachePrepStmts", "true"); config.addDataSourceProperty("prepStmtCacheSize", "250"); config.addDataSourceProperty("prepStmtCacheSqlLimit", "2048"); config.setLeakDetectionThreshold(TimeUnit.SECONDS.toMillis(30)); config.setValidationTimeout(TimeUnit.MINUTES.toMillis(1)); config.setMaximumPoolSize(40); config.setMinimumIdle(0); config.setMaxLifetime(TimeUnit.MINUTES.toMillis(2)); // 120 seconds max life time config.setIdleTimeout(TimeUnit.MINUTES.toMillis(1)); // minutes config.setConnectionTimeout(TimeUnit.MINUTES.toMillis(5)); // millis config.setConnectionTestQuery("/* ping */ SELECT 1"); return config; } here's how my queries look like : public ArrayList<LocationType> getLocationTypes() { ArrayList<LocationType> locationTypes = new ArrayList<>(); Connection connection = null; PreparedStatement pstmt = null; ResultSet resultSet = null; try { connection = DataSource.getInstance().getConnection(); pstmt = connection.prepareStatement("SELECT\n" + " location_type_id,\n" + " location_type_name\n" + "FROM tablename;"); resultSet = pstmt.executeQuery(); while (resultSet.next()) { locationTypes.add(new LocationType(resultSet.getInt("location_type_id"), resultSet.getString("location_type_name"))); } } catch (Exception e) { e.printStackTrace(); } finally { if (resultSet != null) try { resultSet.close(); } catch (SQLException e) { } if (pstmt != null) try { pstmt.close(); } catch (SQLException e) { } if (connection != null) try { connection.close(); } catch (SQLException e) { } } return locationTypes; } I've already tried increasing the connectionLeakDetection, max connection and minimum idle but none of that solved the issue. I have read that it could be caused by the machine(low resources) and connections being closed, I think however, none of these causes the issue. I noticed that some long queries in my code are now being detected as connection leak, even though I am not calling their methods. I hope you guys could help. This is the stack trace : at com..database.DataSource.getConnection(DataSource.java:148)
  2. 0

    HikariCP Connection leak

    Stack Overflow | 4 months ago | Exotical
    java.lang.Exception: Apparent connection leak detected
  3. 0

    Connection leak

    GitHub | 3 months ago | monktastic
    java.lang.Exception: Apparent connection leak detected
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

  5. 0

    Memory leaks once in a while

    GitHub | 5 months ago | MattVibes
    java.lang.Exception: Apparent connection leak detected

    Not finding the right solution?
    Take a tour to get the most out of Samebug.

    Tired of useless tips?

    Automated exception search integrated into your IDE

    Root Cause Analysis

    1. java.lang.Exception

      Apparent connection leak detected I already checked and made sure all my sql codes has a call to close method. Here's my HikariConfig : private HikariConfig hikariConfig() { HikariConfig config = new HikariConfig(); config.setDriverClassName(CLASS_FOR_NAME); config.setJdbcUrl(HOST); config.setUsername(USER); config.setPassword(PASS); config.addDataSourceProperty("cachePrepStmts", "true"); config.addDataSourceProperty("prepStmtCacheSize", "250"); config.addDataSourceProperty("prepStmtCacheSqlLimit", "2048"); config.setLeakDetectionThreshold(TimeUnit.SECONDS.toMillis(30)); config.setValidationTimeout(TimeUnit.MINUTES.toMillis(1)); config.setMaximumPoolSize(40); config.setMinimumIdle(0); config.setMaxLifetime(TimeUnit.MINUTES.toMillis(2)); // 120 seconds max life time config.setIdleTimeout(TimeUnit.MINUTES.toMillis(1)); // minutes config.setConnectionTimeout(TimeUnit.MINUTES.toMillis(5)); // millis config.setConnectionTestQuery("/* ping */ SELECT 1"); return config; } here's how my queries look like : public ArrayList<LocationType> getLocationTypes() { ArrayList<LocationType> locationTypes = new ArrayList<>(); Connection connection = null; PreparedStatement pstmt = null; ResultSet resultSet = null; try { connection = DataSource.getInstance().getConnection(); pstmt = connection.prepareStatement("SELECT\n" + " location_type_id,\n" + " location_type_name\n" + "FROM tablename;"); resultSet = pstmt.executeQuery(); while (resultSet.next()) { locationTypes.add(new LocationType(resultSet.getInt("location_type_id"), resultSet.getString("location_type_name"))); } } catch (Exception e) { e.printStackTrace(); } finally { if (resultSet != null) try { resultSet.close(); } catch (SQLException e) { } if (pstmt != null) try { pstmt.close(); } catch (SQLException e) { } if (connection != null) try { connection.close(); } catch (SQLException e) { } } return locationTypes; } I've already tried increasing the connectionLeakDetection, max connection and minimum idle but none of that solved the issue. I have read that it could be caused by the machine(low resources) and connections being closed, I think however, none of these causes the issue. I noticed that some long queries in my code are now being detected as connection leak, even though I am not calling their methods. I hope you guys could help. This is the stack trace : at com..database.DataSource.getConnection(DataSource.java:148)

      at com.database.databaseServices.MileageReportService.MileageService.getMonthlySummaryBySID()
    2. com.database.databaseServices
      MileageService.getMonthlySummaryBySID
      1. com.database.databaseServices.MileageReportService.MileageService.getMonthlySummaryBySID(MileageService.java:27)
      1 frame
    3. com.views.reports
      MileageReport.lambda$generateReport$61446b05$1
      1. com.views.reports.mileage.MileageReport.lambda$generateReport$61446b05$1(MileageReport.java:103)
      1 frame
    4. Java RT
      Method.invoke
      1. sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      2. sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      3. sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      4. java.lang.reflect.Method.invoke(Method.java:498)
      4 frames