Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

decorrelatedJitter and fullJitter delay calculation overflows #2115

Closed
kgrits opened this issue Jun 10, 2022 · 4 comments
Closed

decorrelatedJitter and fullJitter delay calculation overflows #2115

kgrits opened this issue Jun 10, 2022 · 4 comments
Labels
type: bug A general bug
Milestone

Comments

@kgrits
Copy link

kgrits commented Jun 10, 2022

Bug Report

Current Behavior

  1. Delay.decorrelatedJitter() always returns the same value. If used with default setup - 0.

  2. I couldn't find any limitation on attempts in ConnectionWatchdog, that's why I decided to test Delay.fullJitter() with a high number of attempts (100+). If I use any other value for base except the default one I get IllegalArgumentException: bound must be greater than origin.

Stack trace
Exception in thread "main" java.lang.IllegalArgumentException: bound must be greater than origin
	at java.base/jdk.internal.util.random.RandomSupport.checkRange(RandomSupport.java:246)
	at java.base/java.util.random.RandomGenerator.nextLong(RandomGenerator.java:739)
	at java.base/java.util.concurrent.ThreadLocalRandom.nextLong(ThreadLocalRandom.java:484)
	at io.lettuce.core.resource.Delay.randomBetween(Delay.java:331)
	at io.lettuce.core.resource.FullJitterDelay.createDelay(FullJitterDelay.java:57)

Input Code

decorrelatedJitter
Delay delay = Delay.decorrelatedJitter().get();
for (int i = 0; i < 10; i++) {
    System.out.println(delay.createDelay(i).toMillis());
}
fullJitter
var delay = Delay.fullJitter(Duration.ZERO, Duration.ofSeconds(30), 2, TimeUnit.MILLISECONDS);
for (int i = 0; i < 100; i++) {
    System.out.println(delay.createDelay(i).toMillis());
}

Expected behavior/code

Environment

  • Lettuce version(s): 6.1.8.RELEASE
  • Redis version: N/A
@mp911de
Copy link
Collaborator

mp911de commented Jun 13, 2022

@mp911de mp911de closed this as not planned Won't fix, can't repro, duplicate, stale Jun 13, 2022
@mp911de mp911de added the status: invalid An issue that we don't feel is valid label Jun 13, 2022
@kgrits
Copy link
Author

kgrits commented Jun 13, 2022

Hey, thanks for your reply. My bad! Though I updated my code to start attempts at 1 and still got the same behavior for both Delay's.

Delay delay = Delay.decorrelatedJitter().get();
for (int i = 1; i < 10; i++) {
    System.out.println(delay.createDelay(i).toMillis());
}
Delay delay = Delay.fullJitter(Duration.ZERO, Duration.ofSeconds(30), 2, TimeUnit.MILLISECONDS);
for (int i = 1; i < 100; i++) {
    System.out.println(delay.createDelay(i).toMillis());
}

@mp911de mp911de reopened this Jun 13, 2022
@mp911de mp911de added type: bug A general bug and removed status: invalid An issue that we don't feel is valid labels Jun 13, 2022
@mp911de
Copy link
Collaborator

mp911de commented Jun 13, 2022

Upon further investigation, DecorrelatedJitterDelay has a bug where the previous delay conversion was missing.

The full jitter implementation returns zero upon reaching 2^63 because the long value range exceeds. We should update the code to use the upper bound for jittering instead of falling back to zero.

@mp911de mp911de changed the title Delay.decorrelatedJitter and Delay.fullJitter decorrelatedJitter and fullJitter delay calculation overflows Jun 13, 2022
mp911de added a commit that referenced this issue Jun 13, 2022
Lettuce now considers overflow states and the previous delay time unit conversion is correct to avoid zero-delays.
mp911de added a commit that referenced this issue Jun 13, 2022
Lettuce now considers overflow states and the previous delay time unit conversion is correct to avoid zero-delays.
@mp911de
Copy link
Collaborator

mp911de commented Jun 13, 2022

That's fixed now, thanks for reporting the issue.

@mp911de mp911de closed this as completed Jun 13, 2022
@mp911de mp911de added this to the 6.1.9.RELEASE milestone Jun 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug A general bug
Projects
None yet
Development

No branches or pull requests

2 participants