in curator-framework/src/main/java/org/apache/curator/framework/state/ConnectionStateManager.java [277:310]
private void checkSessionExpiration() {
if ((currentConnectionState == ConnectionState.SUSPENDED) && (startOfSuspendedEpoch != 0)) {
long elapsedMs = System.currentTimeMillis() - startOfSuspendedEpoch;
long useSessionTimeoutMs = getUseSessionTimeoutMs();
if (elapsedMs >= useSessionTimeoutMs) {
startOfSuspendedEpoch =
System.currentTimeMillis(); // reset startOfSuspendedEpoch to avoid spinning on this session
// expiration injection CURATOR-405
log.warn(
"Session timeout has elapsed while SUSPENDED. Injecting a session expiration. Elapsed ms: {}. Adjusted session timeout ms: {}",
elapsedMs,
useSessionTimeoutMs);
try {
if (lastExpiredInstanceIndex == client.getZookeeperClient().getInstanceIndex()) {
// last expiration didn't work for this instance, so event thread is dead and a reset is needed.
// CURATOR-561
client.getZookeeperClient().reset();
} else {
lastExpiredInstanceIndex = client.getZookeeperClient().getInstanceIndex();
client.getZookeeperClient().getZooKeeper().getTestable().injectSessionExpiration();
}
} catch (Exception e) {
log.error("Could not inject session expiration", e);
}
}
} else if (currentConnectionState == ConnectionState.LOST) {
try {
// give ConnectionState.checkTimeouts() a chance to run, reset ensemble providers, etc.
client.getZookeeperClient().getZooKeeper();
} catch (Exception e) {
log.error("Could not get ZooKeeper", e);
}
}
}