KEYCLOAK-17870 Fix ConcurrentModificationException upon liquibase initialization
This commit is contained in:
parent
df4f88a0c8
commit
3e91e6f966
1 changed files with 9 additions and 5 deletions
|
@ -48,6 +48,7 @@ import org.keycloak.models.KeycloakSession;
|
|||
import org.keycloak.models.KeycloakSessionFactory;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import liquibase.changelog.ChangeLogHistoryServiceFactory;
|
||||
|
||||
/**
|
||||
|
@ -61,15 +62,18 @@ public class DefaultLiquibaseConnectionProvider implements LiquibaseConnectionPr
|
|||
|
||||
private int indexCreationThreshold;
|
||||
|
||||
private volatile boolean initialized = false;
|
||||
private static final AtomicBoolean INITIALIZATION = new AtomicBoolean(false);
|
||||
|
||||
@Override
|
||||
public LiquibaseConnectionProvider create(KeycloakSession session) {
|
||||
if (!initialized) {
|
||||
synchronized (this) {
|
||||
if (!initialized) {
|
||||
if (! INITIALIZATION.get()) {
|
||||
// We need critical section synchronized on some static final field, otherwise
|
||||
// e.g. several Undertows or parallel model tests could attempt initializing Liquibase
|
||||
// in the same JVM at the same time which leads to concurrency failures
|
||||
synchronized (INITIALIZATION) {
|
||||
if (! INITIALIZATION.get()) {
|
||||
baseLiquibaseInitialization();
|
||||
initialized = true;
|
||||
INITIALIZATION.set(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue