1
0
Fork 0
mirror of https://github.com/overleaf/overleaf.git synced 2025-04-11 02:37:21 +00:00

add a timeout for getPreviousDocOps

it uses several redis operations and this makes it prone to subsequent
timeouts if getDoc succeeds but is slow
This commit is contained in:
Brian Gough 2017-06-23 15:50:21 +01:00
parent 9f31402fb4
commit 963e513057
2 changed files with 32 additions and 0 deletions
services/document-updater
app/coffee
test/unit/coffee/RedisManager

View file

@ -141,6 +141,7 @@ module.exports = RedisManager =
callback null, version
getPreviousDocOps: (doc_id, start, end, callback = (error, jsonOps) ->) ->
timer = new metrics.Timer("redis.get-prev-docops")
rclient.llen keys.docOps(doc_id: doc_id), (error, length) ->
return callback(error) if error?
rclient.get keys.docVersion(doc_id: doc_id), (error, version) ->
@ -168,6 +169,8 @@ module.exports = RedisManager =
ops = jsonOps.map (jsonOp) -> JSON.parse jsonOp
catch e
return callback(e)
timeSpan = timer.done()
return callback(new Error("redis getPreviousDocOps exceeded timeout")) if timeSpan > MAX_REDIS_REQUEST_LENGTH
callback null, ops
DOC_OPS_TTL: 60 * minutes

View file

@ -265,6 +265,35 @@ describe "RedisManager", ->
it "should log out the problem", ->
@logger.warn.called.should.equal true
describe "with a slow request to redis", ->
beforeEach ->
@first_version_in_redis = 30
@version = 70
@length = @version - @first_version_in_redis
@start = 50
@end = 60
@ops = [
{ "mock": "op-1" },
{ "mock": "op-2" }
]
@jsonOps = @ops.map (op) -> JSON.stringify op
@rclient.llen = sinon.stub().callsArgWith(1, null, @length)
@rclient.get = sinon.stub().callsArgWith(1, null, @version.toString())
@clock = sinon.useFakeTimers();
@rclient.lrange = (key, start, end, cb) =>
@clock.tick(6000);
cb(null, @jsonOps)
@RedisManager.getPreviousDocOps(@doc_id, @start, @end, @callback)
afterEach ->
@clock.restore()
it 'should return an error', ->
@callback
.calledWith(new Error("redis getPreviousDocOps exceeded timeout"))
.should.equal true
describe "updateDocument", ->
beforeEach ->
@rclient.set = sinon.stub()