impossibl / pgjdbc-ng

A new JDBC driver for PostgreSQL aimed at supporting the advanced features of JDBC and Postgres
https://impossibl.github.io/pgjdbc-ng
Other
596 stars 108 forks source link

Connection leak when timing out connection attempts #585

Open lloydyellowbrick opened 1 year ago

lloydyellowbrick commented 1 year ago

Hi there 😄 We have been noticing a leaked connection under certain circumstances when connecting to a PG database with this driver.

Here is the simple program I am connecting with:

import java.util.Properties;
import java.sql.*;

public class Main {

  public static void main(String[] args) {
      Properties props = new Properties();
      props.put("user", "{username}");
      props.put("password", "{password}");

      String url = "jdbc:pgsql:{database}?unixsocket=/tmp/.s.PGSQL.5432";
      DriverManager.setLoginTimeout(30);

      try (Connection conn = DriverManager.getConnection(url, props)) {
          try (Statement stmt = conn.createStatement()) {
                stmt.execute("drop table if exists bar;");
                stmt.execute("create table bar(i int);");
          }
      } catch (Exception e) {
          e.printStackTrace();
          try {
            Thread.sleep(10000000);
        } catch (InterruptedException e1) {
            e1.printStackTrace();
        }
      }
  }
}

To repro the issue:

Observations: