Skip to content

Commit

Permalink
only apply timeout/backoff logic to timer-based reconnection attempts…
Browse files Browse the repository at this point in the history
…, not credentials or discovery driven events
  • Loading branch information
andrewazores committed Sep 7, 2023
1 parent 19a6d93 commit aa90a69
Showing 1 changed file with 17 additions and 19 deletions.
36 changes: 17 additions & 19 deletions src/main/java/io/cryostat/discovery/DiscoveryStorage.java
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,23 @@ private void checkNonConnectedTargetJvmIds() {
testNonConnectedTargets(
entry -> {
TargetNode targetNode = entry.getKey();
ConnectionAttemptRecord attemptRecord = nonConnectableTargets.get(entry);
// TODO make this configurable, use an exponential backoff, have a
// maximum retry policy, etc.
long nextAttempt =
(attemptRecord.attemptCount * attemptRecord.attemptCount)
+ attemptRecord.lastAttemptTimestamp;
attemptRecord.attemptCount++;
long now = clock.now().getEpochSecond();
if (now < nextAttempt) {
return false;
}
long elapsed =
attemptRecord.lastAttemptTimestamp
- attemptRecord.firstAttemptTimestamp;
if (elapsed > ConnectionAttemptRecord.MAX_ATTEMPT_INTERVAL) {
return false;
}
return testJvmId(targetNode.getTarget());
});
}
Expand All @@ -220,25 +237,6 @@ private void testNonConnectedTargets(Predicate<Entry<TargetNode, UUID>> predicat
for (var entry : copy.entrySet()) {
executor.execute(
() -> {
// TODO make this configurable, use an exponential backoff, have a
// maximum retry policy, etc.
ConnectionAttemptRecord attemptRecord = entry.getValue();
long nextAttempt =
(attemptRecord.attemptCount * attemptRecord.attemptCount)
+ attemptRecord.lastAttemptTimestamp;
attemptRecord.attemptCount++;
long now = clock.now().getEpochSecond();
long elapsed =
attemptRecord.lastAttemptTimestamp
- attemptRecord.firstAttemptTimestamp;
if (elapsed > ConnectionAttemptRecord.MAX_ATTEMPT_INTERVAL) {
nonConnectableTargets.remove(entry.getKey());
return;
}
if (now < nextAttempt) {
return;
}
attemptRecord.lastAttemptTimestamp = now;
try {
if (predicate.test(entry.getKey())) {
nonConnectableTargets.remove(entry.getKey());
Expand Down

0 comments on commit aa90a69

Please sign in to comment.