mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
Include COUNT in lock and make RND per-process incase randomBytes blocks
This commit is contained in:
parent
d15a22be26
commit
4ab4e27724
1 changed files with 3 additions and 2 deletions
|
@ -9,6 +9,8 @@ crypto = require "crypto"
|
|||
|
||||
HOST = os.hostname()
|
||||
PID = process.pid
|
||||
RND = crypto.randomBytes(4).toString('hex')
|
||||
COUNT = 0
|
||||
|
||||
module.exports = LockManager =
|
||||
LOCK_TEST_INTERVAL: 50 # 50ms between each test of the lock
|
||||
|
@ -20,8 +22,7 @@ module.exports = LockManager =
|
|||
# to prevent accidental unlocking by multiple processes
|
||||
randomLock : () ->
|
||||
time = Date.now()
|
||||
RND = crypto.randomBytes(4).toString('hex')
|
||||
return "locked:host=#{HOST}:pid=#{PID}:random=#{RND}:time=#{time}"
|
||||
return "locked:host=#{HOST}:pid=#{PID}:random=#{RND}:time=#{time}:count=#{COUNT++}"
|
||||
|
||||
unlockScript: 'if redis.call("get", KEYS[1]) == ARGV[1] then return redis.call("del", KEYS[1]) else return 0 end';
|
||||
|
||||
|
|
Loading…
Reference in a new issue