mirror of
https://github.com/discourse/discourse.git
synced 2024-11-22 15:25:35 +08:00
FIX: properly count DistributedMutex locking attempts
When originally introduced, `attempts` was only used in the read-only check
context.
With the introduction of the exponential backoff in cda370db
, `attempts` was
also used to count loop iterations, but was left inside the if block instead of
being incremented every loop, meaning the exponential backoff was only
happening when the site was recently readonly.
Co-authored-by: jbrw <jamie.wilson@discourse.org>
This commit is contained in:
parent
2b9fa41a6e
commit
618fb5b34d
|
@ -88,14 +88,11 @@ class DistributedMutex
|
|||
# Exponential backoff, max duration 1s
|
||||
interval = attempts < 10 ? (0.001 * 2**attempts) : 1
|
||||
sleep interval
|
||||
attempts += 1
|
||||
|
||||
# in readonly we will never be able to get a lock
|
||||
if @using_global_redis && Discourse.recently_readonly?
|
||||
attempts += 1
|
||||
|
||||
if attempts > CHECK_READONLY_ATTEMPTS
|
||||
raise Discourse::ReadOnly
|
||||
end
|
||||
if @using_global_redis && Discourse.recently_readonly? && attempts > CHECK_READONLY_ATTEMPTS
|
||||
raise Discourse::ReadOnly
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue
Block a user