Ensure map storage providers are closed upon session close

Fixes: #14730
This commit is contained in:
Hynek Mlnarik 2022-10-05 11:02:24 +02:00 committed by Michal Hajas
parent 425b6b8df2
commit 36a1ce6a1a
2 changed files with 6 additions and 0 deletions

View file

@ -108,6 +108,7 @@ public abstract class AbstractMapProviderFactory<T extends Provider, V extends A
protected MapStorage<V, M> getStorage(KeycloakSession session) {
ProviderFactory<MapStorageProvider> storageProviderFactory = getProviderFactoryOrComponentFactory(session, storageConfigScope);
final MapStorageProvider factory = storageProviderFactory.create(session);
session.enlistForClose(factory);
return factory.getStorage(modelType);
}

View file

@ -127,6 +127,11 @@ public class DefaultKeycloakSession implements KeycloakSession {
@Override
public void enlistForClose(Provider provider) {
for (Provider p : closable) {
if (p == provider) { // Do not add the same provider twice
return;
}
}
closable.add(provider);
}