Spring Boot 2.6.4 Liquibase 4.5.0

Given an empty database. When the database is concurrently initialized by two Spring Boot apps, then a race condition may occur which causes one of the apps to fail.

This issue has been reported to the Liquibase team as liquibase#2083. It seems it has been fixed in Liquibase 4.6.2. No GA version of Spring Boot currently ships with Liquibase > 4.5.0.

Excerpt of the log of the app which starts successfully:

2022-02-24 13:17:41.134  INFO 1 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Start completed.
2022-02-24 13:17:42.890  INFO 1 --- [           main] liquibase.lockservice                    : Successfully acquired change log lock
2022-02-24 13:17:48.171  INFO 1 --- [           main] liquibase.changelog                      : Creating database history table with name: public.databasechangelog
2022-02-24 13:17:48.189  INFO 1 --- [           main] liquibase.changelog                      : Reading from public.databasechangelog
2022-02-24 13:17:49.305  INFO 1 --- [           main] liquibase.lockservice                    : Successfully released change log lock
2022-02-24 13:17:49.310  INFO 1 --- [           main] liquibase.lockservice                    : Successfully acquired change log lock
2022-02-24 13:17:49.312  WARN 1 --- [           main] liquibase.hub                            : Skipping auto-registration
2022-02-24 13:17:49.340  INFO 1 --- [           main] liquibase.changelog                      : Table users created
2022-02-24 13:17:49.354  INFO 1 --- [           main] liquibase.changelog                      : ChangeSet migrations/db.changelog-0.1.0.xml::0::foo ran successfully in 32ms
2022-02-24 13:17:52.502  INFO 1 --- [           main] liquibase.lockservice                    : Successfully released change log lock

Excerpt of the log of the app which fails to start:

2022-02-24 13:17:36.965  INFO 1 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Start completed.
2022-02-24 13:17:45.304  INFO 1 --- [           main] l.lockservice.StandardLockService        : Waiting for changelog lock....
2022-02-24 13:17:55.376  INFO 1 --- [           main] l.lockservice.StandardLockService        : Successfully acquired change log lock
2022-02-24 13:18:02.871  INFO 1 --- [           main] l.c.StandardChangeLogHistoryService      : Reading from public.databasechangelog
2022-02-24 13:18:03.819 ERROR 1 --- [           main] liquibase.changelog.ChangeSet            : Change Set classpath:/migrations/db.changelog-0.1.0.xml::0::foo failed.  Error: ERROR: relation "users" already exists
2022-02-24 13:18:03.837  INFO 1 --- [           main] l.lockservice.StandardLockService        : Successfully released change log lock
2022-02-24 13:18:03.841  WARN 1 --- [           main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'liquibase' defined in class path resource [org/springframework/boot/autoconfigure/liquibase/LiquibaseAutoConfiguration$LiquibaseConfiguration.class]: Invocation of init method failed; nested exception is liquibase.exception.MigrationFailedException: Migration failed for change set classpath:/migrations/db.changelog-0.1.0.xml::0::foo: Reason: liquibase.exception.DatabaseException: ERROR: relation "users" already exists
2022-02-24 13:18:03.842  INFO 1 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Shutdown initiated...
2022-02-24 13:18:03.869  INFO 1 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Shutdown completed.
2022-02-24 13:18:03.901  INFO 1 --- [           main] o.apache.catalina.core.StandardService   : Stopping service [Tomcat]
2022-02-24 13:18:03.986  INFO 1 --- [           main] ConditionEvaluationReportLoggingListener : Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2022-02-24 13:18:04.069 ERROR 1 --- [           main] o.s.boot.SpringApplication               : Application run failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'liquibase' defined in class path resource [org/springframework/boot/autoconfigure/liquibase/LiquibaseAutoConfiguration$LiquibaseConfiguration.class]: Invocation of init method failed; nested exception is liquibase.exception.MigrationFailedException: Migration failed for change set classpath:/migrations/db.changelog-0.1.0.xml::0::foo:
     Reason: liquibase.exception.DatabaseException: ERROR: relation "users" already exists
Caused by: liquibase.exception.MigrationFailedException: Migration failed for change set classpath:/migrations/db.changelog-0.1.0.xml::0::foo:
     Reason: liquibase.exception.DatabaseException: ERROR: relation "users" already exists
Caused by: liquibase.exception.DatabaseException: ERROR: relation "users" already exists

Comment From: snicoll

You've already requested an upgrade, which has been declined and I don't really understand what you're hoping to happen with a separate issue.

This is an issue in Liquibase. If you are affected you can override liquibase as explained in the reference documentation using the liquibase.version property.