Skip to content

[FlightSQL] Statement.execute(String) can leak server prepared-statement handles when reused #1129

@xborder

Description

@xborder

Describe the bug, including details regarding any error messages, version, and platform.

When reusing the same JDBC Statement and calling execute(String) multiple times, the Flight SQL JDBC path creates a new prepared statement on each call, but previous prepared handles are not closed before being replaced in client tracking state.

This means only the latest handle is guaranteed to be closed when the statement is closed. On stateful Flight SQL servers, this can leak server-side resources associated with older handles.

Repro

try (Connection connection = DriverManager.getConnection(jdbcUrl, properties);
     Statement statement = connection.createStatement()) {

  for (int i = 1; i <= n; i++) {
    String sql = "SELECT " + i;
    boolean isResultSet = statement.execute(sql);
    if (isResultSet) {
      try (ResultSet rs = statement.getResultSet()) {
        while (rs.next()) { /* consume */ }
      }
    }
  }
}

Raised in #1090 (comment)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type: bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions