Skip to content

Is it desired behavior to sleep, even after the last retry in the lock function? #7

Description

@wingunder

If a lock was not obtained in the lock function, is it desired behavior to sleep (in line 80), even after the last retry?
I think that the last retry's sleep will be a waste of time, if the lock was not obtained.

redlock-rb/redlock.rb

Lines 55 to 57 in 97be08b

def lock(resource,ttl)
val = get_unique_lock_id
@retry_count.times {

redlock-rb/redlock.rb

Lines 79 to 81 in 97be08b

# Wait a random delay before to retry
sleep(rand(@retry_delay).to_f/1000)
}

If my argument holds, how about:

for i in 0..(retry_count-1)

  # The major part of the lock function goes here.

  # Don't sleep if it's the last retry.
  if (i != retry_count-1)
    # Wait a random part of retry_delay, before retrying.
    sleep(rand(@retry_delay).to_f/1000)
  end
end

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions