Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

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

Open
#1,129 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
55/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Quiet
Tech stack
java
Domain
databases

Research direction

Start at the Flight SQL JDBC implementation of Statement.execute(String) and trace how prepared-statement handles are replaced and closed; the issue does not name a file or test. Reproduce the loop against a stateful Flight SQL server, then verify that each prior handle is released before the next is tracked and that Statement.close still cleans up the final handle.

Written by the indexing model from the issue text.

Description

Type: bug
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 https://github.com/apache/arrow-java/pull/1090#discussion_r3132344585

Dominant language
Java
Stars
95
Forks
154
Avg merge
2d 10h
Merged PRs (30d)
11

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from apache/arrow-java

All issues in apache/arrow-java

Similar issues

More Java issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.