From 9e4fc3f49151cd32bb84dbe8e5bd57a1050d6a69 Mon Sep 17 00:00:00 2001 From: Alexander Schwartz Date: Tue, 12 Dec 2023 12:55:33 +0100 Subject: [PATCH] Keep workaround permanently for concurrent shutdowns of embedded Infinispan Closes #9871 Signed-off-by: Alexander Schwartz --- .../infinispan/InfinispanNotificationsManager.java | 10 +--------- .../DefaultInfinispanConnectionProviderFactory.java | 10 ++++------ 2 files changed, 5 insertions(+), 15 deletions(-) diff --git a/model/infinispan/src/main/java/org/keycloak/cluster/infinispan/InfinispanNotificationsManager.java b/model/infinispan/src/main/java/org/keycloak/cluster/infinispan/InfinispanNotificationsManager.java index 7e8b7f42fa..7f9bc7bd1e 100644 --- a/model/infinispan/src/main/java/org/keycloak/cluster/infinispan/InfinispanNotificationsManager.java +++ b/model/infinispan/src/main/java/org/keycloak/cluster/infinispan/InfinispanNotificationsManager.java @@ -235,16 +235,8 @@ public class InfinispanNotificationsManager { // TODO: Look at CacheEventConverter stuff to possibly include value in the event and avoid additional remoteCache request try { listenersExecutor.submit(() -> { - - /* - workaround for Infinispan 12.1.7.Final to prevent a deadlock while - DefaultInfinispanConnectionProviderFactory is shutting down PersistenceManagerImpl - that acquires a writeLock and this get that acquires a readLock. - First seen with https://issues.redhat.com/browse/ISPN-13664 and still occurs probably due to - https://issues.redhat.com/browse/ISPN-13666 in 13.0.10 - Tracked in https://github.com/keycloak/keycloak/issues/9871 - */ Object value = DefaultInfinispanConnectionProviderFactory.runWithReadLockOnCacheManager(() -> + // We've seen deadlocks in Infinispan 14.x when shutting down Infinispan concurrently, therefore wrapping this remoteCache.get(key) ); eventReceived(key, (Serializable) value); diff --git a/model/infinispan/src/main/java/org/keycloak/connections/infinispan/DefaultInfinispanConnectionProviderFactory.java b/model/infinispan/src/main/java/org/keycloak/connections/infinispan/DefaultInfinispanConnectionProviderFactory.java index f224f888d3..06852af106 100755 --- a/model/infinispan/src/main/java/org/keycloak/connections/infinispan/DefaultInfinispanConnectionProviderFactory.java +++ b/model/infinispan/src/main/java/org/keycloak/connections/infinispan/DefaultInfinispanConnectionProviderFactory.java @@ -89,12 +89,10 @@ public class DefaultInfinispanConnectionProviderFactory implements InfinispanCon } /* - workaround for Infinispan 12.1.7.Final to prevent a deadlock while - DefaultInfinispanConnectionProviderFactory is shutting down PersistenceManagerImpl - that acquires a writeLock and this removal that acquires a readLock. - First seen with https://issues.redhat.com/browse/ISPN-13664 and still occurs probably due to - https://issues.redhat.com/browse/ISPN-13666 in 13.0.10 - Tracked in https://github.com/keycloak/keycloak/issues/9871 + Workaround for Infinispan 12.1.7.Final and tested until 14.0.19.Final to prevent a deadlock while + DefaultInfinispanConnectionProviderFactory is shutting down. Kept as a permanent solution and considered + good enough after a lot of analysis went into this difficult to reproduce problem. + See https://github.com/keycloak/keycloak/issues/9871 for the discussion. */ public static void runWithReadLockOnCacheManager(Runnable task) { Lock lock = DefaultInfinispanConnectionProviderFactory.READ_WRITE_LOCK.readLock();