-
Notifications
You must be signed in to change notification settings - Fork 38.8k
Description
Torsten Krah opened SPR-11573 and commented
I've traced down a race condition after a few hours and found the fix. So I wonder if this can be included in the default configuration of the ConnectionProperties
for H2EmbeddedDatabaseConfigurer
.
Per default DB_CLOSE_ON_EXIT
is true
. Thus, if the test VM exits, the Spring ApplicationContext
gets closed, but H2 also registers a shutdown hook: the DatabaseCloser thread shuts down the database in parallel. As a consequence, all scripts configured via <jdbc:script location="..." execution="DESTROY" />
(that should be run at closing time) fail because the database was already shutdown.
It would be good if the following line in H2EmbeddedDatabaseConfigurer.configureConnectionProperties()
...
properties.setUrl(String.format("jdbc:h2:mem:%s;DB_CLOSE_DELAY=-1", databaseName));
... could be modified as follows:
properties.setUrl(String.format("jdbc:h2:mem:%s;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=false", databaseName));
This would result in ...
<jdbc:script location="classpath:emptyTables.sql" execution="DESTROY" />
not emitting errors about missing tables.
Affects: 4.0.2