Repository navigation
fix(jdbc): close the product-version statement (#92) - #128
Merged
Merged
Conversation
resolveDatabaseProductVersion wrapped only the result set in try-with-resources, so the statement stayed open after the version was read. Wrap the statement too, and pin the leak with a statement-count test that also confirms the cached second call opens nothing.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
LibsqlDatabaseMetaData.resolveDatabaseProductVersion()ranconnection.createStatement().executeQuery(...)in a try-with-resources that wrapped only the result set. The statement stayed open after every uncached version lookup. The statement and its result set now open in one try-with-resources, so both close, the result set first.The new leak-count case counts statements created through the test connection. The second case pins the cache, so a future uncached second lookup shows up as a second statement.
Contract basis. Hrana 3 is the source of truth for transport, values, and metadata,
java.sqlis the source of truth for the JDBC surface, and xerial/sqlite-jdbc is a behavioral reference only. This change is protocol-neutral. The product version still comes fromselect sqlite_version()throughexecute, and JDBC owns statement cleanup.Red and green
Red at base
8754013with only the new tests applied. The leak-count case fails for the intended reason. The cache case passes at base, because caching already exists; it is a guard, not a red case.Green at head
0b33b7a.Cache observation
getDatabaseProductVersion()twice through one metadata instance creates one statement. The first call opens, reads, and closes it. The second call readscachedDatabaseProductVersionand opens nothing.getDatabaseProductVersionOpensOneStatementAcrossTwoCallsasserts the count stays at one.Verification
Base
8754013c90b0299f7e87147702663eaa9646c12, head0b33b7a93b292a9159bba1086a9078a34be80633../mvnw -pl libsql-jdbc test -Dtest=LibsqlDatabaseMetaDataTestat base and head./mvnw -pl libsql-jdbc test -Dtest='LibsqlDatabaseMetaDataTest#getDatabaseProductVersion*'./mvnw -pl libsql-jdbc test -Dtest=LibsqlDatabaseMetaDataTest./mvnw -pl libsql-jdbc test./mvnw -pl libsql-conformance -am verify./mvnw -pl libsql-conformance -am -Pxerial-control verify./mvnw spotless:check./mvnw test./mvnw -pl libsql-conformance -am verify -Dit.test=MetadataLeakTest./mvnw -pl libsql-jdbc -am package -DskipTests./mvnw -pl libsql-jdbc testthree times per side, interleavedDivergences and scope
No protocol divergence. The protocol has no statement lifecycle field, so JDBC defines it.
Caching semantics are unchanged. Issue #112 owns the failed-lookup cache and the closed-connection behavior. This PR changes statement ownership only.
Files
libsql-jdbc/src/main/java/com/github/magnusp/libsql/jdbc/LibsqlDatabaseMetaData.java,libsql-jdbc/src/test/java/com/github/magnusp/libsql/jdbc/LibsqlDatabaseMetaDataTest.java.Fixes #92