The GitHub Actions job "MySQL Integration Tests" on 
pekko-persistence-jdbc.git/close-leaked-slick-databases has succeeded.
Run started by GitHub user pjfanning (triggered by pjfanning).

Head commit for run:
2c2a9e284224b6a63d98ee82e76a202e147f9f27 / PJ Fanning 
<[email protected]>
Close Slick databases that are created but never closed

Motivation:
`DefaultSlickDatabaseProvider` creates a new `Database` (and therefore a new
connection pool with its own threads) for every call that does not use
`use-shared-db`. The journal, snapshot store and read journal close the database
they requested, but three callers never do:

- `JdbcDurableStateStoreProvider` creates an eager database and neither closes 
it
  nor registers a shutdown hook, so its connection pool outlives the actor 
system.
- `SchemaUtilsImpl` creates a database for every `createIfNotExists`,
  `dropIfExists` and `applyScript` call and drops the reference to it.
- `JournalMigrator` and `SnapshotMigrator` open one and two databases
  respectively and offer no way to close them.

Modification:
- `JdbcDurableStateStoreProvider` registers `db.close()` on actor system
  termination when it owns the database, the same as `JdbcReadJournal` does.
- `SchemaUtilsImpl` registers the databases it creates for closing on actor
  system termination. The database is deliberately not closed as soon as the
  script has been applied, because that would drop an H2 in-memory database
  together with the schema that was just created.
- `JournalMigrator` and `SnapshotMigrator` implement `AutoCloseable` and close
  the databases they opened. Shared databases (`use-shared-db`) are left alone
  in all three cases, since those are owned by the actor system.

Result:
Connection pools that this library creates are closed again, instead of living
on until the JVM exits.

Tests:
- sbt "core/testOnly 
org.apache.pekko.persistence.jdbc.state.JdbcDurableStateStoreProviderSpec 
org.apache.pekko.persistence.jdbc.testkit.internal.SchemaUtilsImplSpec" - 
passed (both fail without the fix)
- sbt "migratorIntegration/testOnly 
org.apache.pekko.persistence.jdbc.migrator.MigratorCloseTest" - passed
- sbt "core/testOnly *H2*" - 217 passed, 1 failed: 
H2ScalaCurrentEventsByTagTest "should complete without any gaps in case events 
are being persisted when the query is executed", which fails the same way on an 
unmodified checkout of main
- sbt "core/mimaReportBinaryIssues" - passed
- scalafmt --mode diff-ref=upstream/main - no changes

References:
None - found while reviewing the main sources for resource leaks

Report URL: 
https://github.com/apache/pekko-persistence-jdbc/actions/runs/34202308963

With regards,
GitHub Actions via GitBox


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

Reply via email to