You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
"Deadlock found when trying to get lock" in file locking #20555
We have a ton of following entries, they appear dozens to hundreds of times per second:
{"reqId":"96M5ZtaObvQI\/q+FUTeB","remoteAddr":"93.202.76.110","app":"core","message":"Exception while scanning file \"msrex\/files_versions\/owncloud\/support\/XXXX\/XXXX/XXXX9\": An exception occurred while executing 'INSERT INTO `oc_file_locks` (`key`,`lock`,`ttl`) SELECT ?,?,? FROM `oc_file_locks` WHERE `key` = ? HAVING COUNT(*) = 0' with params [\"files\\\/7a4d0ec119d9e99086554694bf6fa2bc\", 1, 1447758814, \"files\\\/7a4d0ec119d9e99086554694bf6fa2bc\"]:\n\nSQLSTATE[40001]: Serialization failure: 1213 Deadlock found when trying to get lock; try restarting transaction","level":0,"time":"2015-11-17T10:13:34+00:00","method":"GET","url":"\/owncloud\/index.php\/apps\/files\/ajax\/scan.php?force=false&dir=&requesttoken=TOKEN"}
I had to hack the apps/files/ajax/scan.php file to not do anything to provide at least some kind of server uptime. This should not hurt the server but is a big hack.
Before the fix: deadlock error on one or all files, mv still finished with "423 locked".
After the fix: mv continues undisturbed and ls directly returns the old file list and never blocks!
I tried those several times (before and after).
@icewind1991 it looks like your commit fixes the issue ! (or at least my version of it)
So it looks like the scanner itself needs its own exclusive look to prevent double-scanning ?
As advised, I now ran the commands in CLI mysql and after restarting the CLI session it seems that the values were kept (contrary to my previous belief).
After following the steps from #20555 (comment) the "ls" call still blocks and the log still shows
{"reqId":"f5Qq6fIDKMny4nuH7CV\/","remoteAddr":"127.0.0.1","app":"core","message":"Exception while scanning file \"files\/test\/P1100409.JPG\": An exception occurred while executing 'UPDATE `oc_file_locks` SET `lock` = `lock` + 1, `ttl` = ? WHERE `key` = ? AND `lock` >= 0' with params [1461574469, \"files\\\/09915c88bfd09feb443462ab2efdaed9\"]:\n\nSQLSTATE[HY000]: General error: 1205 Lock wait timeout exceeded; try restarting transaction","level":0,"time":"2016-04-25T07:55:20+00:00","method":"PROPFIND","url":"\/owncloud\/remote.php\/webdav\/test\/","user":"admin"}
Retested both cases with @icewind1991's PR #24205 and with the proper transaction mode, it still works fine in a non-blocking manner (returns 423 Locked directly)
It looks like this deadlock was also reproducible with two concurrent "ls" aka PROPFIND on the to-be-rescanned folder: #24260 (comment).
Two concurrent PROPFINDs is more likely to be the cause of this error happening often, since multiple clients might query for changes. This, more often than a MOVE + PROPFIND.
Activity
LukasReschke commentedon Nov 17, 2015
I had to hack the
apps/files/ajax/scan.phpfile to not do anything to provide at least some kind of server uptime. This should not hurt the server but is a big hack.(somewhat related to #20545)
nickvergessen commentedon Nov 17, 2015
As per our docs we need READ_COMMITED
So running
should fix the problem
DeepDiver1975 commentedon Nov 17, 2015
We are setting the transaction level in the ctor of the connection - what's going wrong here?
DeepDiver1975 commentedon Nov 17, 2015
core/lib/private/db/connection.php
Line 135 in 705d208
nickvergessen commentedon Nov 17, 2015
maybe the account we use is not allowed to run this command?
DeepDiver1975 commentedon Nov 17, 2015
we explicit set the transaction level on each connection we open
icewind1991 commentedon Nov 17, 2015
Try running
To check that the transaction level is set correctly
LukasReschke commentedon Nov 17, 2015
This is 5.5.45-MariaDB from OpenSUSE.
39 remaining items
icewind1991 commentedon Apr 22, 2016
@PVince81 can you try 6881034
PVince81 commentedon Apr 22, 2016
Turns out I wasn't able to reproduce the original issue without this commit. It only happened once.
But this variation of the steps where cadaver B (the move) runs first and implicitly scans followed by cadaver A produces the deadlock errors.
Here are the updated steps:
sleep(1)AFTER acquireLock to make sure the scanner lock takes longer. I also added a logging statement that logs$fileso I can observe the progress.For every file that is to be scanned I see the deadlock message appearing.
And this is consistent!
Even weirder is that at the end, cadaver A still fails with "423 locked" and in the end the folder did not get renamed.
Next step: @icewind1991's commit
PVince81 commentedon Apr 22, 2016
@icewind1991 I tested with your commit with both steps and could not make the deadlock issue appear again:
lsbeforemv("Deadlock found when trying to get lock" in file locking #20555 (comment))mvbeforels("Deadlock found when trying to get lock" in file locking #20555 (comment))mvcontinues undisturbed andlsdirectly returns the old file list and never blocks!I tried those several times (before and after).
@icewind1991 it looks like your commit fixes the issue ! (or at least my version of it)
So it looks like the scanner itself needs its own exclusive look to prevent double-scanning ?
nickvergessen commentedon Apr 25, 2016
Which is wrong and which is what I said last week already.
#20555 (comment)
That should then cause an immediate return with "locked"
nickvergessen commentedon Apr 25, 2016
Please verify and then close the issue
PVince81 commentedon Apr 25, 2016
As advised, I now ran the commands in CLI mysql and after restarting the CLI session it seems that the values were kept (contrary to my previous belief).
After following the steps from #20555 (comment) the "ls" call still blocks and the log still shows
PVince81 commentedon Apr 25, 2016
Retested both cases with @icewind1991's PR #24205 and with the proper transaction mode, it still works fine in a non-blocking manner (returns 423 Locked directly)
PVince81 commentedon Apr 26, 2016
It looks like this deadlock was also reproducible with two concurrent "ls" aka PROPFIND on the to-be-rescanned folder: #24260 (comment).
Two concurrent PROPFINDs is more likely to be the cause of this error happening often, since multiple clients might query for changes. This, more often than a MOVE + PROPFIND.
The PR above fixes that too.
lock commentedon Aug 4, 2019
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.