Skip to content

Commit

Permalink
Handle case of expired locks
Browse files Browse the repository at this point in the history
  • Loading branch information
glpatcern committed Nov 29, 2021
1 parent 5452088 commit a12b247
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
6 changes: 4 additions & 2 deletions src/core/wopiutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,8 @@ def retrieveWopiLock(fileid, operation, lock, acctok, overridefilename=None):
encacctok = flask.request.args['access_token'][-20:] if 'access_token' in flask.request.args else 'N/A'
lockcontent = st.getlock(acctok['endpoint'], overridefilename if overridefilename else acctok['filename'], acctok['userid'])
if not lockcontent:
log.warning('msg="%s" user="%s" filename="%s" token="%s" error="WOPI lock not found, ignoring"' %
(operation.title(), acctok['userid'][-20:], acctok['filename'], encacctok))
return None # no pre-existing lock found, or error attempting to read it: assume it does not exist
try:
# check validity: a lock is deemed expired if the most recent between its expiration time and the last
Expand Down Expand Up @@ -308,10 +310,10 @@ def storeWopiLock(fileid, operation, lock, oldlock, acctok, isoffice):
# another session was faster than us, or the file was already WOPI-locked:
# get the lock that was set
retrievedLock = retrieveWopiLock(fileid, operation, lock, acctok)
if not compareWopiLocks(retrievedLock, (oldlock if oldlock else lock)):
if retrievedLock and not compareWopiLocks(retrievedLock, (oldlock if oldlock else lock)):
return makeConflictResponse(operation, retrievedLock, lock, oldlock, acctok['filename'], \
'The file was locked by another online editor')
# else it's our lock, refresh it and return
# else it's our lock or it had expired, refresh it and return
st.refreshlock(acctok['endpoint'], acctok['filename'], acctok['userid'], _makeLock(lock))
log.info('msg="%s" filename="%s" token="%s" lock="%s" result="refreshed"' %
(operation.title(), acctok['filename'], flask.request.args['access_token'][-20:], lock))
Expand Down
5 changes: 4 additions & 1 deletion src/core/xrootiface.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,12 @@ def _xrootcmd(endpoint, cmd, subcmd, userid, args):
if rc != '0':
# failure: get info from stderr, log and raise
msg = res[1][res[1].find('=')+1:].strip('\n')
if ENOENT_MSG.lower() in msg or 'unable to get attribute' in msg or EXCL_XATTR_MSG in msg:
if ENOENT_MSG.lower() in msg or 'unable to get attribute' in msg:
log.info('msg="Invoked xroot on non-existing entity" cmd="%s" subcmd="%s" args="%s" error="%s" rc="%s"' % \
(cmd, subcmd, args, msg, rc.strip('\00')))
elif EXCL_XATTR_MSG in msg:
log.info('msg="Invoked setxattr on an already locked entity" cmd="%s" subcmd="%s" args="%s" error="%s" rc="%s"' % \
(cmd, subcmd, args, msg, rc.strip('\00')))
else:
log.error('msg="Error with xroot" cmd="%s" subcmd="%s" args="%s" error="%s" rc="%s"' % \
(cmd, subcmd, args, msg, rc.strip('\00')))
Expand Down

0 comments on commit a12b247

Please sign in to comment.