-
Notifications
You must be signed in to change notification settings - Fork 81
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
chore: note it is safe to auto-reconnect #126
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -169,15 +169,17 @@ def initialize(connection) | |
def lock(resource, val, ttl, allow_new_lock) | ||
recover_from_script_flush do | ||
@redis.with { |conn| | ||
conn.call('EVALSHA', Scripts::LOCK_SCRIPT_SHA, 1, resource, val, ttl, allow_new_lock) | ||
# NOTE: is not idempotent and unsafe to retry | ||
conn.call_once('EVALSHA', Scripts::LOCK_SCRIPT_SHA, 1, resource, val, ttl, allow_new_lock) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I assume you mean unsafe if you're using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ah, comment got out of date with my code. I changed my mind that locking probably isn't idempotent and change the code from There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. now the logic and comments are in sync unlock/lock # NOTE: is not idempotent and unsafe to retry
conn.call_once(...) load_scripts/get remaining ttl # NOTE: is idempotent and safe to retry
conn.call(...) |
||
} | ||
end | ||
end | ||
|
||
def unlock(resource, val) | ||
recover_from_script_flush do | ||
@redis.with { |conn| | ||
conn.call('EVALSHA', Scripts::UNLOCK_SCRIPT_SHA, 1, resource, val) | ||
# NOTE: is not idempotent and unsafe to retry | ||
conn.call_once('EVALSHA', Scripts::UNLOCK_SCRIPT_SHA, 1, resource, val) | ||
} | ||
end | ||
rescue | ||
|
@@ -187,6 +189,7 @@ def unlock(resource, val) | |
def get_remaining_ttl(resource) | ||
recover_from_script_flush do | ||
@redis.with { |conn| | ||
# NOTE: is idempotent and safe to retry | ||
conn.call('EVALSHA', Scripts::PTTL_SCRIPT_SHA, 1, resource) | ||
} | ||
end | ||
|
@@ -205,6 +208,7 @@ def load_scripts | |
|
||
@redis.with do |connnection| | ||
scripts.each do |script| | ||
# NOTE: is idempotent and safe to retry | ||
connnection.call('SCRIPT', 'LOAD', script) | ||
end | ||
end | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
aside, interesting logic inside sidekiq where it defines
redis(&block)
https://github.com/sidekiq/sidekiq/blob/v7.0.5/lib/sidekiq/config.rb#L118-L133I'm doing some more comparisons since we got a flood of OpenSSL errors for about 10 minutes today which Heroku https://help.heroku.com/70UD7VSR/why-am-i-seeing-syscall-returned-5-errno-0-state-sslv3-tls-write-client-hello-when-trying-to-connect-to-heroku-redis reports as "because the maximum number of clients to Redis has been reached" which appears to be what happened
Nothing this PR would address, I don't think, but worth sharing in the upgrade changes discussion, I think.