فهرست منبع

put a 5 second timeout in getting redis lock

Brian Gough 9 سال پیش
والد
کامیت
54c0fc1180
1فایلهای تغییر یافته به همراه7 افزوده شده و 2 حذف شده
  1. 7 2
      services/document-updater/app/coffee/LockManager.coffee

+ 7 - 2
services/document-updater/app/coffee/LockManager.coffee

@@ -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()