mirror of
https://github.com/overleaf/overleaf.git
synced 2025-03-11 22:23:37 +00:00
improve unlock error handling
This commit is contained in:
parent
b2b4bc44df
commit
c11618b475
2 changed files with 37 additions and 18 deletions
services/document-updater
|
@ -70,6 +70,10 @@ module.exports = LockManager =
|
||||||
|
|
||||||
releaseLock: (doc_id, lockValue, callback)->
|
releaseLock: (doc_id, lockValue, callback)->
|
||||||
key = keys.blockingKey(doc_id:doc_id)
|
key = keys.blockingKey(doc_id:doc_id)
|
||||||
rclient.eval LockManager.unlockScript, 1, key, lockValue, callback
|
rclient.eval LockManager.unlockScript, 1, key, lockValue, (err, result) ->
|
||||||
|
if err?
|
||||||
|
return callback(err)
|
||||||
|
if result? and result isnt 1 # successful unlock should release exactly one key
|
||||||
|
logger.error {doc_id:doc_id, lockValue:lockValue, redis_err:err, redis_result:result}, "unlocking error"
|
||||||
|
return callback(new Error("tried to release timed out lock"))
|
||||||
|
callback(err,result)
|
||||||
|
|
|
@ -8,21 +8,36 @@ doc_id = 5678
|
||||||
SandboxedModule = require('sandboxed-module')
|
SandboxedModule = require('sandboxed-module')
|
||||||
|
|
||||||
describe 'LockManager - releasing the lock', ()->
|
describe 'LockManager - releasing the lock', ()->
|
||||||
|
beforeEach ->
|
||||||
evalStub = sinon.stub().yields(1)
|
@client = {
|
||||||
mocks =
|
|
||||||
"logger-sharelatex": log:->
|
|
||||||
"redis-sharelatex":
|
|
||||||
createClient : ()->
|
|
||||||
auth: ->
|
auth: ->
|
||||||
eval: evalStub
|
eval: sinon.stub()
|
||||||
|
}
|
||||||
|
mocks =
|
||||||
|
"logger-sharelatex":
|
||||||
|
log:->
|
||||||
|
error:->
|
||||||
|
"redis-sharelatex":
|
||||||
|
createClient : () => @client
|
||||||
"./Metrics": {inc: () ->}
|
"./Metrics": {inc: () ->}
|
||||||
|
@LockManager = SandboxedModule.require(modulePath, requires: mocks)
|
||||||
|
@lockValue = "lock-value-stub"
|
||||||
|
|
||||||
LockManager = SandboxedModule.require(modulePath, requires: mocks)
|
describe "when the lock is current", ->
|
||||||
|
beforeEach ->
|
||||||
|
@client.eval = sinon.stub().yields(null, 1)
|
||||||
|
@LockManager.releaseLock doc_id, @lockValue, @callback
|
||||||
|
|
||||||
it 'should put a all data into memory', (done)->
|
it 'should clear the data from redis', ->
|
||||||
lockValue = "lock-value-stub"
|
@client.eval.calledWith(@LockManager.unlockScript, 1, "Blocking:#{doc_id}", @lockValue).should.equal true
|
||||||
LockManager.releaseLock doc_id, lockValue, ->
|
|
||||||
evalStub.calledWith(LockManager.unlockScript, 1, "Blocking:#{doc_id}", lockValue).should.equal true
|
|
||||||
done()
|
|
||||||
|
|
||||||
|
it 'should call the callback', ->
|
||||||
|
@callback.called.should.equal true
|
||||||
|
|
||||||
|
describe "when the lock has expired", ->
|
||||||
|
beforeEach ->
|
||||||
|
@client.eval = sinon.stub().yields(null, 0)
|
||||||
|
@LockManager.releaseLock doc_id, @lockValue, @callback
|
||||||
|
|
||||||
|
it 'should return an error if the lock has expired', ->
|
||||||
|
@callback.calledWith(new Error("tried to release timed out lock")).should.equal true
|
||||||
|
|
Loading…
Reference in a new issue