Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SNOW-1903844 Avoid closing already closed SnowflakeDatabaseMetaDataResultSet #2058

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

fabiencelier
Copy link
Contributor

@fabiencelier fabiencelier commented Jan 30, 2025

Overview

SNOW-1903844

Pre-review self checklist

  • PR branch is updated with all the changes from master branch
  • The code is correctly formatted (run mvn -P check-style validate)
  • New public API is not unnecessary exposed (run mvn verify and inspect target/japicmp/japicmp.html)
  • The pull request name is prefixed with SNOW-XXXX:
  • Code is in compliance with internal logging requirements

External contributors - please answer these questions before submitting a pull request. Thanks!

  1. What GitHub issue is this PR addressing? Make sure that there is an accompanying issue to your PR.

    Issue: SNOW-1903844: Closing an already closed SnowflakeDatabaseMetaDataResultSet triggers logs in DriverManager.getLogWriter() #2057

  2. Fill out the following pre-review checklist:

    • I am adding a new automated test(s) to verify correctness of my new code
    • I am adding new logging messages
    • I am modifying authorization mechanisms
    • I am adding new credentials
    • I am modifying OCSP code
    • I am adding a new dependency or upgrading an existing one
    • I am adding new public/protected component not marked with @SnowflakeJdbcInternalApi (note that public/protected methods/fields in classes marked with this annotation are already internal)
  3. Please describe how your code solves the related issue.

Do nothing if already closed

@fabiencelier fabiencelier requested a review from a team as a code owner January 30, 2025 14:00
getStatement().close(); // should close both result set and statement.
} catch (SQLException ex) {
logger.debug("Failed to close", ex);
if (!isClosed()) { // Nothing to do if already closed.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should not close the resource at the last row

I wrote a small test for this behaviour but of course the logs need to be check manually:

@Test
  public void testCloseOnceMetadataResultSet() throws SQLException {
    String tableName = TestUtil.randomTableName("SNOW-1903844");
    try (Connection con = getConnection();
        Statement stmt = con.createStatement()) {
      stmt.execute("CREATE OR REPLACE TABLE " + tableName + " (a text)");
      try (ResultSet columns =
          con.getMetaData().getColumns(con.getCatalog(), con.getSchema(), tableName.toUpperCase(), null)) {
        int count = 0;
        while (columns.next()) {
          ++count;
        }
        assertEquals(1, count);
      }
    }
  }

Checking isClosed seems to solve the local problem, but not the root cause of the issue which in my opinion is calling close on wrong result set in


@fabiencelier you can check that when there is showObjectResultSet.close(); instead the log about closed RS disappears and this is the issue also in other places in SnowflakeDatabaseMetaData when we run the query and repack the result set

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants