put a 5 second timeout in getting redis lock

This commit is contained in:
Brian Gough 2017-07-11 14:25:59 +01:00
parent ffea31290c
commit 54c0fc1180

View file

@ -14,6 +14,8 @@ PID = process.pid
RND = crypto.randomBytes(4).toString('hex')
COUNT = 0
MAX_REDIS_REQUEST_LENGTH = 5000 # 5 seconds
module.exports = LockManager =
LOCK_TEST_INTERVAL: 50 # 50ms between each test of the lock
MAX_TEST_INTERVAL: 1000 # back off to 1s between each test of the lock
@ -37,8 +39,11 @@ module.exports = LockManager =
return callback(err) if err?
if gotLock == "OK"
metrics.inc "doc-not-blocking"
profile.log("got lock").end()
callback err, true, lockValue
timeTaken = profile.log("got lock").end()
if timeTaken > MAX_REDIS_REQUEST_LENGTH
callback err, false # took too long to get the lock, bail out
else
callback err, true, lockValue
else
metrics.inc "doc-blocking"
profile.log("doc is locked").end()