pjfanning opened a new pull request, #606:
URL: https://github.com/apache/pekko-persistence-jdbc/pull/606

   ### 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 then 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 new specs fail without the production change
   - `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". That test fails the 
same way on an unmodified checkout of `main`, so it is pre-existing and 
unrelated.
   - `sbt "core/mimaReportBinaryIssues"` - passed
   - `scalafmt --mode diff-ref=upstream/main` - no changes
   
   ### References
   None - found while reviewing the main sources for resource leaks
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


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

Reply via email to