The GitHub Actions job "Basic checks" on 
pekko-projection.git/jdbc-try-with-resource has failed.
Run started by GitHub user pjfanning (triggered by pjfanning).

Head commit for run:
cc9fc84286bd74b19541b63747d22e04eb11679d / PJ Fanning 
<[email protected]>
fix leaked Statement/ResultSet in JdbcSessionUtil.tryWithResource

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

Report URL: https://github.com/apache/pekko-projection/actions/runs/34063711404

With regards,
GitHub Actions via GitBox


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to