When exiting, try to clean up any taken update locks

Signed-off-by: Pablo Carranza Velez <pablo@resin.io>
This commit is contained in:
Pablo Carranza Velez 2018-01-26 10:56:52 -08:00
parent 2ed3c832ac
commit ef849f8d82

View File

@ -20,6 +20,13 @@ lockFileOnHost = (appId, serviceName) ->
return path.join(constants.rootMountPoint, exports.lockPath(appId, serviceName), 'resin-updates.lock')
exports.UpdatesLockedError = class UpdatesLockedError extends TypedError
locksTaken = []
# Try to clean up any existing locks when the program exits
process.on 'exit', ->
for lockName in locksTaken
try
lockFile.unlockSync(lockName)
exports.lock = do ->
_lock = new Lock()
@ -28,9 +35,9 @@ exports.lock = do ->
takeTheLock = ->
Promise.try ->
return if !appId?
locksTaken = []
dispose = (release) ->
Promise.map locksTaken, (lockName) ->
Promise.map _.clone(locksTaken), (lockName) ->
_.pull(locksTaken, lockName)
lockFile.unlockAsync(lockName)
.finally ->
release()