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

Respect retry_delay in all cases #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions src/redlock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@ impl Redlock {
u64 + 2);

'attempts: while attempts < self.retry_count {
if attempts > 0 {
thread::sleep(self.get_retry_timeout());
}

attempts += 1;

// Start time of this attempt
Expand Down Expand Up @@ -163,7 +167,6 @@ impl Redlock {

// fail: releases all aquired locks and retry
lock.unlock().is_ok(); // Just ingore the result
thread::sleep(self.get_retry_timeout());
continue 'attempts;
}
Err(_) => {
Expand All @@ -172,7 +175,6 @@ impl Redlock {
// the timeout
if errors > self.quorum {
lock.unlock().is_ok(); // Just ingore the result
thread::sleep(self.get_retry_timeout());
continue 'attempts;
}
}
Expand All @@ -191,6 +193,10 @@ impl Redlock {
let mut attempts = 0;

'attempts: while attempts < self.retry_count {
if attempts > 0 {
thread::sleep(self.get_retry_timeout());
}

attempts += 1;

let mut waitings = self.clients.len();
Expand Down Expand Up @@ -218,7 +224,6 @@ impl Redlock {
// This attempt is doomed to fail, will retry after
// the timeout
if errors >= self.quorum {
thread::sleep(self.get_retry_timeout());
continue 'attempts;
}
}
Expand Down Expand Up @@ -345,9 +350,6 @@ mod tests {

assert!(lock.expiration > start);
assert!(lock.expiration < start.add(one_second));
assert!(REDLOCK.lock(resource_name, one_second).is_err());

thread::sleep(one_second);

assert!(REDLOCK.lock(resource_name, one_second).is_ok());
}
Expand Down