Skip to content

Commit b466f4d

Browse files
committed
KEYCLOAK-5910 Retry sending notification when remote cache is unavailable
1 parent b8e5fd2 commit b466f4d

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

model/infinispan/src/main/java/org/keycloak/cluster/infinispan/InfinispanNotificationsManager.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,10 @@
5050
import org.keycloak.cluster.ClusterListener;
5151
import org.keycloak.cluster.ClusterProvider;
5252
import org.keycloak.common.util.ConcurrentMultivaluedHashMap;
53+
import org.keycloak.common.util.Retry;
5354
import org.keycloak.executors.ExecutorsProvider;
5455
import org.keycloak.models.KeycloakSession;
56+
import org.infinispan.client.hotrod.exceptions.HotRodClientException;
5557

5658
/**
5759
* Impl for sending infinispan messages across cluster and listening to them
@@ -153,7 +155,21 @@ void notify(String taskKey, ClusterEvent event, boolean ignoreSender, ClusterPro
153155
.put(eventKey, wrappedEvent, 120, TimeUnit.SECONDS);
154156
} else {
155157
// Add directly to remoteCache. Will notify remote listeners on all nodes in all DCs
156-
workRemoteCache.put(eventKey, wrappedEvent, 120, TimeUnit.SECONDS);
158+
Retry.executeWithBackoff((int iteration) -> {
159+
try {
160+
workRemoteCache.put(eventKey, wrappedEvent, 120, TimeUnit.SECONDS);
161+
} catch (HotRodClientException re) {
162+
if (logger.isDebugEnabled()) {
163+
logger.debugf(re, "Failed sending notification to remote cache '%s'. Key: '%s', iteration '%s'. Will try to retry the task",
164+
workRemoteCache.getName(), eventKey, iteration);
165+
}
166+
167+
// Rethrow the exception. Retry will take care of handle the exception and eventually retry the operation.
168+
throw re;
169+
}
170+
171+
}, 10, 10);
172+
157173
}
158174
}
159175

0 commit comments

Comments
 (0)