Scope error while migrating in test container

Hi everyone. I am getting this errors while migrating my database inside test container. I am using PostgreSQL 13, test container com.dimafeng/testcontainers-scala-postgresql 0.38.6 and Liquibase 4.1.1.

INFO: Error getting default schema
java.lang.NullPointerException
	at java.base/java.util.TreeMap.rotateRight(TreeMap.java:2240)
	at java.base/java.util.TreeMap.fixAfterInsertion(TreeMap.java:2272)
	at java.base/java.util.TreeMap.put(TreeMap.java:580)
	at liquibase.util.SmartMap.put(SmartMap.java:77)
	at liquibase.Scope.getSingleton(Scope.java:311)
	at liquibase.database.AbstractJdbcDatabase.getConnectionSchemaName(AbstractJdbcDatabase.java:360)
	at liquibase.database.AbstractJdbcDatabase.getDefaultSchemaName(AbstractJdbcDatabase.java:325)
	at liquibase.changelog.ChangeLogParameters.<init>(ChangeLogParameters.java:61)
	at liquibase.Liquibase.<init>(Liquibase.java:123)

/** some production classes here

   at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
   at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
   at java.base/java.lang.Thread.run(Thread.java:834)

And then:

INFO: Successfully acquired change log lock
нояб. 17, 2020 11:53:50 PM liquibase.lockservice
INFO: Successfully acquired change log lock
нояб. 17, 2020 11:53:52 PM liquibase.changelog
INFO: Creating database history table with name: public.databasechangelog
нояб. 17, 2020 11:53:52 PM liquibase.changelog
INFO: Creating database history table with name: public.databasechangelog
нояб. 17, 2020 11:53:52 PM liquibase.changelog
INFO: Reading from public.databasechangelog
нояб. 17, 2020 11:53:52 PM liquibase.changelog
INFO: Reading from public.databasechangelog
нояб. 17, 2020 11:53:52 PM liquibase.lockservice
INFO: Successfully released change log lock
нояб. 17, 2020 11:53:52 PM liquibase.lockservice
INFO: Successfully released change log lock

[info]   liquibase.exception.LiquibaseException: java.lang.RuntimeException: Cannot end scope aikoqztxww when currently at scope spqahgmasy
[info]   at liquibase.Liquibase.runInScope(Liquibase.java:2282)
[info]   at liquibase.Liquibase.update(Liquibase.java:215)
[info]   at liquibase.Liquibase.update(Liquibase.java:201)
[info]   at liquibase.Liquibase.update(Liquibase.java:197)
[info]   at liquibase.Liquibase.update(Liquibase.java:189)
/** Some production again
[info]   ...
[info]   Cause: java.lang.RuntimeException: Cannot end scope aikoqztxww when currently at scope spqahgmasy
[info]   at liquibase.Scope.exit(Scope.java:209)
[info]   at liquibase.Scope.child(Scope.java:171)
[info]   at liquibase.Scope.child(Scope.java:159)
[info]   at liquibase.Scope.child(Scope.java:138)
[info]   at liquibase.Liquibase.runInScope(Liquibase.java:2277)
[info]   at liquibase.Liquibase.update(Liquibase.java:215)
[info]   at liquibase.Liquibase.update(Liquibase.java:201)
[info]   at liquibase.Liquibase.update(Liquibase.java:197)
[info]   at liquibase.Liquibase.update(Liquibase.java:189)
/** And some production here

I tried to google this “scope” thing but no luck. The only thing i found is this report on wildfly: https://github.com/jamesnetherton/wildfly-liquibase/issues/82

It seems to happens only when i have two test suit in app with database container in each.

It looks like somehow there was one Liquibase instance which tried to migrate two databases concurrently.

We are getting the same error while running multiple schema upgrades in parallel

the static property of Scope.class : private static ScopeManager scopeManager seems to be not thread safe.

executor.invokeAll(
     schemas.map { 
          Callable { createNewLiquibaseInstanceAndRun(it) }
     }
)
1 Like

We just removed parallel test execution for now.

Should’ve just add semaphore :melting_face: