Repository navigation
Conversation
pjfanning
added a commit
to pjfanning/incubator-pekko-projection
that referenced
this pull request
Sep 6, 2026
Motivation: The new spec file was untracked when `scalafmt --mode diff-ref` was run, so it was not reformatted and the `Code is formatted` and `Check Code Style` jobs failed. Modification: Replace the matcher form that scalafmt rewrites into `(x should be).theSameInstanceAs(y)` with a plain reference-equality assertion, and format the file. Result: `sbt checkCodeStyle` passes. Tests: - sbt checkCodeStyle - success - sbt "jdbc/test" - 31 passed References: Refs apache#618
Motivation: `tryWithResource` takes the resource as a by-name parameter and evaluates it twice: once when calling `func`, and once again in the `finally` block. The resource handed to `func` is therefore never closed, while a second resource is created only to be closed immediately. Every call site in `JdbcOffsetStore` and `SlickOffsetStore` leaks a `Statement`/`PreparedStatement`, which accumulates on the physical connection when the `JdbcSession` is backed by a connection pool. For `tryWithResource(stmt.executeQuery())` in `JdbcOffsetStore.readOffset` and `readManagementState` it also means the query is executed twice and the first `ResultSet` is leaked. Modification: Evaluate the by-name parameter once into a local val and use that instance for both `func` and `close()`. Result: The resource passed to `func` is the one that gets closed, no extra resource is created, and queries are executed once. Tests: - sbt "jdbc/test" - 31 passed (new JdbcSessionUtilSpec fails on all 3 cases without the fix) - sbt "jdbc/mimaReportBinaryIssues" - success - scalafmt --mode diff-ref=upstream/main - no changes - sbt headerCreateAll - header added to the new spec References: None - found during a resource-leak audit of the main sources
Motivation: The new spec file was untracked when `scalafmt --mode diff-ref` was run, so it was not reformatted and the `Code is formatted` and `Check Code Style` jobs failed. Modification: Replace the matcher form that scalafmt rewrites into `(x should be).theSameInstanceAs(y)` with a plain reference-equality assertion, and format the file. Result: `sbt checkCodeStyle` passes. Tests: - sbt checkCodeStyle - success - sbt "jdbc/test" - 31 passed References: Refs apache#618
pjfanning
force-pushed
the
jdbc-try-with-resource
branch
from
October 27, 2026 08:38
47ceecc to
d648454
Compare
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.
Motivation
JdbcSessionUtil.tryWithResourcetakes the resource as a by-name parameter and evaluates it twice: once when callingfunc, and once again in thefinallyblock.So the resource handed to
funcis never closed, and a second one is created just to be closed. Consequences:JdbcOffsetStore(lines 69, 80, 98, 114, 182, 200, 240, 281, 301) andSlickOffsetStore(lines 169, 176, 187, 193) leak aStatement/PreparedStatementon every call. When theJdbcSessionis backed by a connection pool (connection returned to the pool rather than physically closed) these accumulate on the physical connection and can exhaust server-side cursors.tryWithResource(stmt.executeQuery())inJdbcOffsetStore.readOffsetandreadManagementStateexecutes the query a second time and leaks the firstResultSet.Modification
Evaluate the by-name parameter once into a local val, and use that instance both for
funcand forclose().Result
The resource passed to
funcis the one that gets closed, no extra resource is created, and each query is executed once.Tests
JdbcSessionUtilSpecasserts that exactly one resource is created and that the instance passed to the function is the one closed (also on function failure, and whenclose()throwsSQLException). All 3 cases fail before the fix.sbt "jdbc/test"- 31 passedsbt "jdbc/mimaReportBinaryIssues"- successsbt checkCodeStyle- successsbt headerCreateAll- header added to the new specReferences
None - found during a resource-leak audit of the main sources