Skip to content

Commit

Permalink
No delay applied after the last connection attempt has been made (#709)
Browse files Browse the repository at this point in the history
Closes #702
  • Loading branch information
jwaeab committed Sep 2, 2024
1 parent baeac37 commit a760817
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Changes
## Version 5.0.5

* RetryPolicy: After failing the last connection attempt, the retry time is still applied - Issue #702
* Define logging levels formally - Issue #666
* Deprecate cassandra-all to use testContainers instead - Issue #701
* Update Mockito and JUnit versions - Issue #687
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,26 +140,35 @@ private static void handleRetry(
final int port,
final long timeout)
{
LOG.warn("Unable to connect through CQL using {}:{}, retrying.", host, port);
LOG.warn("Unable to connect through CQL using {}:{}.", host, port);
long delay = retryPolicy.currentDelay(attempt);
long currentTime = System.currentTimeMillis();
long endTime = currentTime + timeout;
if (currentTime + delay > endTime)
{
delay = timeout;
}
LOG.warn("Connection failed in attempt {} of {}. Retrying in {} seconds.",
attempt, retryPolicy.getMaxAttempts(), TimeUnit.MILLISECONDS.toSeconds(delay));
try

if (attempt == retryPolicy.getMaxAttempts())
{
Thread.sleep(delay);
LOG.error("All connection attempts failed ({} were made)!", attempt);
}
catch (InterruptedException ie)
else
{
LOG.error(
"InterruptedException caught during the delay time, while trying to reconnect to Cassandra. Reason: ",
ie);
LOG.warn("Connection attempt {} of {} failed. Retrying in {} seconds.",
attempt,
retryPolicy.getMaxAttempts(),
TimeUnit.MILLISECONDS.toSeconds(delay));
try
{
Thread.sleep(delay);
}
catch (InterruptedException ie)
{
LOG.error("Exception caught during the delay time, while trying to reconnect to Cassandra.", ie);
}
}

}

@Override
Expand Down

0 comments on commit a760817

Please sign in to comment.