mirror of
https://github.com/discourse/discourse.git
synced 2024-11-22 08:57:10 -06:00
FIX: Off-by-one error setting the distributed mutex key to expire
Accounting for fractional seconds, a distributed mutex can be held for almost a full second longer than its validity. For example: if we grab the lock at 10.5 seconds passed the epoch with a validity of 5 seconds, the lock would be released at 16 seconds passed the epoch. However, in this case assuming that all other processing takes a negligible amount of time, the key would be expired at 15.5 seconds passed the epoch. Using expireat, the key is now expired exactly when the lock is released.
This commit is contained in:
parent
e7a511fc7f
commit
7c7098c700
@ -95,7 +95,7 @@ class DistributedMutex
|
||||
result =
|
||||
redis.multi do
|
||||
redis.set key, expire_time.to_s
|
||||
redis.expire key, validity
|
||||
redis.expireat key, expire_time + 1
|
||||
end
|
||||
|
||||
got_lock = !result.nil?
|
||||
|
Loading…
Reference in New Issue
Block a user