Description
Edit: steps here #28981 (comment)
Observed on 10.0.3 RC1.
Steps
All I did was delete a bunch of files within a folder with desktop client 2.3.3rc2.
Expected
All files deleted
Actual
The first deleted file IMG_1472.JPG did not get deleted. Sync client reports locking error.
Log contains integrity check error which likely exited the PHP request and didn't release the locks.
Server Environment
ownCloud Server 10.0.3RC1
openSUSE Leap 42.2
apache2-2.4.23-8.9.1.x86_64
apache2-mod_php7-7.0.7-14.9.1.x86_64
user-key encryption enabled
folder is shared with one user and one link share.
Client Environment
openSUSE Leap 42.3
Desktop client 2.3.3rc2
Investigation
First DELETE entry in owncloud.log:
{
"reqId": "Wbbhw38AAAIAAE6ypX8AAAAM",
"level": 4,
"time": "2017-09-11T19:19:32+00:00",
"remoteAddr": "77.177.215.233",
"user": "vincent",
"app": "webdav",
"method": "DELETE",
"url": "/remote.php/dav/files/vincent/clientsync/petry/pics/Family_Private/IMG_1472.JPG",
"message": "Exception:
{"Message":"An exception occurred while executing '
UPDATE `oc_filecache` SET `storage` = ?, `path` = ?, `path_hash` = ?, `name` = ?, `parent` =?
WHERE `fileid` = ?' with params [
1,
"files_encryption/keys/files_trashbin/files/IMG_1472.JPG.d1505157572",
"cac9d13bb8d42fd3e25767a9859e2577",
"IMG_1472.JPG.d1505157572",
129728,
127965
]:\n\nSQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '1-cac9d13bb8d42fd3e25767a9859e2577' for key 'fs_storage_path_hash'","Exception":"Doctrine\\\\DBAL\\\\Exception\\\\UniqueConstraintViolationException","Code":0,"Trace":"
#0 /srv/www/htdocs/owncloud/lib/composer/doctrine/dbal/lib/Doctrine/DBAL/DBALException.php(128): Doctrine\DBAL\Driver\AbstractMySQLDriver->convertException('An exception oc...', Object(Doctrine\DBAL\Driver\PDOException))\n
#1 /srv/www/htdocs/owncloud/lib/composer/doctrine/dbal/lib/Doctrine/DBAL/Connection.php(855): Doctrine\DBAL\DBALException::driverExceptionDuringQuery(Object(Doctrine\DBAL\Driver\PDOMySql\Driver), Object(Doctrine\DBAL\Driver\PDOException), 'UPDATE `oc_file...', Array)\n
#2 /srv/www/htdocs/owncloud/lib/private/DB/Connection.php(190): Doctrine\DBAL\Connection->executeQuery('UPDATE `oc_file...', Array, Array, NULL)\n
#3 /srv/www/htdocs/owncloud/lib/private/Files/Cache/Cache.php(534): OC\DB\Connection->executeQuery('UPDATE `oc_file...', Array)\n
#4 /srv/www/htdocs/owncloud/lib/private/Files/Cache/Cache.php(476): OC\Files\Cache\Cache->moveFromCache(Object(OC\Files\Cache\HomeCache), 'files_encryptio...', 'files_encryptio...')\n
#5 /srv/www/htdocs/owncloud/lib/private/Files/Cache/Updater.php(196): OC\Files\Cache\Cache->move('files_encryptio...', 'files_encryptio...')\n
#6 /srv/www/htdocs/owncloud/lib/private/Files/View.php(326): OC\Files\Cache\Updater->renameFromStorage(Object(OCA\Files_Trashbin\Storage), 'files_encryptio...', 'files_encryptio...')\n
#7 /srv/www/htdocs/owncloud/lib/private/Files/View.php(803): OC\Files\View->renameUpdate(Object(OCA\Files_Trashbin\Storage), Object(OCA\Files_Trashbin\Storage), 'files_encryptio...', 'files_encryptio...')\n
#8 /srv/www/htdocs/owncloud/lib/private/Encryption/Keys/Storage.php(284): OC\Files\View->rename('/vincent/files_...', '/vincent/files_...')\n
#9 /srv/www/htdocs/owncloud/lib/private/Files/Storage/Wrapper/Encryption.php(286): OC\Encryption\Keys\Storage->renameKeys('/vincent/files/...', '/vincent/files_...')\n
#10 /srv/www/htdocs/owncloud/lib/private/Files/Storage/Wrapper/Wrapper.php(272): OC\Files\Storage\Wrapper\Encryption->rename('files/clientsyn...', 'files_trashbin/...')\n
#11 /srv/www/htdocs/owncloud/apps/files_trashbin/lib/Storage.php(103): OC\Files\Storage\Wrapper\Wrapper->rename('files/clientsyn...', 'files_trashbin/...')\n
#12 /srv/www/htdocs/owncloud/lib/private/Files/Storage/Wrapper/Wrapper.php(566): OCA\Files_Trashbin\Storage->rename('files/clientsyn...', 'files_trashbin/...')\n
#13 /srv/www/htdocs/owncloud/apps/files_trashbin/lib/Trashbin.php(278): OC\Files\Storage\Wrapper\Wrapper->moveFromStorage(Object(OCA\Files_Trashbin\Storage), 'files/clientsyn...', 'files_trashbin/...')\n
#14 /srv/www/htdocs/owncloud/apps/files_trashbin/lib/Storage.php(185): OCA\Files_Trashbin\Trashbin::move2trash('clientsync/petr...')\n
#15 /srv/www/htdocs/owncloud/apps/files_trashbin/lib/Storage.php(120): OCA\Files_Trashbin\Storage->doDelete('files/clientsyn...', 'unlink')\n
#16 /srv/www/htdocs/owncloud/lib/private/Files/View.php(1123): OCA\Files_Trashbin\Storage->unlink('files/clientsyn...')\n
#17 /srv/www/htdocs/owncloud/lib/private/Files/View.php(693): OC\Files\View->basicOperation('unlink', '/clientsync/pet...', Array)\n
#18 /srv/www/htdocs/owncloud/apps/dav/lib/Connector/Sabre/File.php(366): OC\Files\View->unlink('/clientsync/pet...')\n
#19 /srv/www/htdocs/owncloud/lib/composer/sabre/dav/lib/DAV/Tree.php(179): OCA\DAV\Connector\Sabre\File->delete()\n
#20 /srv/www/htdocs/owncloud/lib/composer/sabre/dav/lib/DAV/CorePlugin.php(287): Sabre\DAV\Tree->delete('files/vincent/c...')\n
#21 [internal function]: Sabre\DAV\CorePlugin->httpDelete(Object(Sabre\HTTP\Request), Object(Sabre\HTTP\Response))\n
#22 /srv/www/htdocs/owncloud/lib/composer/sabre/event/lib/EventEmitterTrait.php(105): call_user_func_array(Array, Array)\n
#23 /srv/www/htdocs/owncloud/lib/composer/sabre/dav/lib/DAV/Server.php(479): Sabre\Event\EventEmitter->emit('method:DELETE', Array)\n
#24 /srv/www/htdocs/owncloud/lib/composer/sabre/dav/lib/DAV/Server.php(254): Sabre\DAV\Server->invokeMethod(Object(Sabre\HTTP\Request), Object(Sabre\HTTP\Response))\n
#25 /srv/www/htdocs/owncloud/apps/dav/lib/Server.php(234): Sabre\DAV\Server->exec()\n
#26 /srv/www/htdocs/owncloud/apps/dav/appinfo/v2/remote.php(31): OCA\DAV\Server->exec()\n
#27 /srv/www/htdocs/owncloud/remote.php(165): require_once('/srv/www/htdocs...')\n
#28 {main}","File":"/srv/www/htdocs/owncloud/lib/composer/doctrine/dbal/lib/Doctrine/DBAL/Driver/AbstractMySQLDriver.php","Line":66,"User":"vincent"}
}
access log grep:
vincent-server:/var/log/apache2 # grep IMG_1472 owncloud.vincentpetry.net-access_log
77.177.215.233 - vincent Wbbhw38AAAIAAE6ypX8AAAAM [11/Sep/2017:21:19:31 +0200] "DELETE /remote.php/dav/files/vincent/clientsync/petry/pics/Family_Private/IMG_1472.JPG HTTP/1.1" 500 686 "-" "Mozilla/5.0 (Linux) mirall/2.3.3rc2 (build 8238)"
77.177.215.233 - vincent Wbbh938AAAIAAE9563sAAAAH [11/Sep/2017:21:20:23 +0200] "DELETE /remote.php/dav/files/vincent/clientsync/petry/pics/Family_Private/IMG_1472.JPG HTTP/1.1" 423 269 "-" "Mozilla/5.0 (Linux) mirall/2.3.3rc2 (build 8238)"
77.177.215.233 - vincent Wbbh@38AAAIAACpyBcIAAAAF [11/Sep/2017:21:20:27 +0200] "DELETE /remote.php/dav/files/vincent/clientsync/petry/pics/Family_Private/IMG_1472.JPG HTTP/1.1" 423 269 "-" "Mozilla/5.0 (Linux) mirall/2.3.3rc2 (build 8238)"
access log from the same time:
77.177.215.233 - vincent Wbbhw38AAAIAAE6ypX8AAAAM [11/Sep/2017:21:19:31 +0200] "DELETE /remote.php/dav/files/vincent/clientsync/petry/pics/Family_Private/IMG_1472.JPG HTTP/1.1" 500 686 "-" "Mozilla/5.0 (Linux) mirall/2.3.3rc2 (build 8238)"
77.177.215.233 - vincent Wbbhw38AAAIAAB2ddrIAAAAA [11/Sep/2017:21:19:31 +0200] "DELETE /remote.php/dav/files/vincent/clientsync/petry/pics/Family_Private/P1130774.webm HTTP/1.1" 204 - "-" "Mozilla/5.0 (Linux) mirall/2.3.3rc2 (build 8238)"
77.177.215.233 - vincent Wbbhw38AAAIAAE9cuygAAAAP [11/Sep/2017:21:19:31 +0200] "DELETE /remote.php/dav/files/vincent/clientsync/petry/pics/Family_Private/P1130704.JPG HTTP/1.1" 204 - "-" "Mozilla/5.0 (Linux) mirall/2.3.3rc2 (build 8238)"
77.177.215.233 - vincent Wbbhw38AAAIAAAu1gdsAAAAE [11/Sep/2017:21:19:31 +0200] "DELETE /remote.php/dav/files/vincent/clientsync/petry/pics/Family_Private/P1130600.webm HTTP/1.1" 204 - "-" "Mozilla/5.0 (Linux) mirall/2.3.3rc2 (build 8238)"
77.177.215.233 - vincent Wbbhw38AAAIAAE9466cAAAAD [11/Sep/2017:21:19:31 +0200] "DELETE /remote.php/dav/files/vincent/clientsync/petry/pics/Family_Private/P1130763.webm HTTP/1.1" 204 - "-" "Mozilla/5.0 (Linux) mirall/2.3.3rc2 (build 8238)"
Looks like a parallel DELETE.
DB entries from after the failure
MariaDB [owncloud]> select * from oc_filecache where path like '%IMG_1472%' order by path;
+--------+---------+----------------------------------------------------------------------------------------------------------------------------+----------------------------------+--------+----------------------------+----------+----------+---------+------------+-----------+----------------------------------+------------------+---------------+-------------+-----------------------------------------------------------------------------------------------------+
| fileid | storage | path | path_hash | parent | name | mimetype | mimepart | size | mtime | encrypted | etag | unencrypted_size | storage_mtime | permissions | checksum |
+--------+---------+----------------------------------------------------------------------------------------------------------------------------+----------------------------------+--------+----------------------------+----------+----------+---------+------------+-----------+----------------------------------+------------------+---------------+-------------+-----------------------------------------------------------------------------------------------------+
| 127967 | 1 | files/clientsync/petry/pics/Family_Private/IMG_1472.JPG | 94339a8a9ef196f7b338d8acf73afe96 | 107288 | IMG_1472.JPG | 15 | 6 | 1492862 | 1500557250 | 1 | 1dc429800fe05c0fc36a496a5668d16d | 0 | 1500557250 | 27 | SHA1:752b3d229855f8f97f4b389e282ca1257c2b7914 MD5:7e3f101c4ed7f4921e2583d6256b38d6 ADLER32:8cc8df85 |
| 127965 | 1 | files_encryption/keys/files/clientsync/petry/pics/Family_Private/IMG_1472.JPG | a2a584c289342fe39befa9d961a2bd0b | 107291 | IMG_1472.JPG | 1 | 2 | 1568 | 1501949677 | 0 | 5985eeed4713c | 0 | 1501949677 | 31 | |
| 127966 | 1 | files_encryption/keys/files/clientsync/petry/pics/Family_Private/IMG_1472.JPG/OC_DEFAULT_MODULE | 092a3ad1a1b8b25b5337c6b6f4aa55ad | 127965 | OC_DEFAULT_MODULE | 1 | 2 | 1568 | 1501949677 | 0 | 5985eeed4bdcf | 0 | 1501949677 | 31 | |
| 127976 | 1 | files_encryption/keys/files/clientsync/petry/pics/Family_Private/IMG_1472.JPG/OC_DEFAULT_MODULE/fileKey | 075d589573878f57448940ec045808fa | 127966 | fileKey | 21 | 14 | 32 | 1501949677 | 0 | 4565f9a1d0e223dd62f6bc75b9967192 | 0 | 1501949677 | 27 | |
| 127977 | 1 | files_encryption/keys/files/clientsync/petry/pics/Family_Private/IMG_1472.JPG/OC_DEFAULT_MODULE/pubShare_0a1edf68.shareKey | f62c36fbf2af0683a8b74097879e7664 | 127966 | pubShare_0a1edf68.shareKey | 21 | 14 | 512 | 1501949677 | 0 | 639ade4f028dc745a6282559f3becfe1 | 0 | 1501949677 | 27 | |
| 127978 | 1 | files_encryption/keys/files/clientsync/petry/pics/Family_Private/IMG_1472.JPG/OC_DEFAULT_MODULE/tingting.shareKey | a9d66d3aebea7776d020c7fe7e4961a9 | 127966 | tingting.shareKey | 21 | 14 | 512 | 1501949677 | 0 | b3ad5c37a87a042199fb1220c4ddd8e0 | 0 | 1501949677 | 27 | |
| 127975 | 1 | files_encryption/keys/files/clientsync/petry/pics/Family_Private/IMG_1472.JPG/OC_DEFAULT_MODULE/vincent.shareKey | 12cb611b6f2eae5b6d81ee7d1febce9c | 127966 | vincent.shareKey | 21 | 14 | 512 | 1501949677 | 0 | 42ddeeb0675e28384ced4627ce5bbbcc | 0 | 1501949677 | 27 | |
| 129729 | 1 | files_encryption/keys/files_trashbin/files/IMG_1472.JPG.d1505157572 | cac9d13bb8d42fd3e25767a9859e2577 | 129728 | IMG_1472.JPG.d1505157572 | 1 | 2 | -1 | 1501949677 | 0 | 59b6e1c412236 | 0 | 1501949677 | 31 | |
+--------+---------+----------------------------------------------------------------------------------------------------------------------------+----------------------------------+--------+----------------------------+----------+----------+---------+------------+-----------+----------------------------------+------------------+---------------+-------------+-----------------------------------------------------------------------------------------------------+
8 rows in set (0.03 sec)
Disk entries
data/vincent/files_trashbin/files/IMG_1472.JPG.d1505157572
data/vincent/files_encryption/keys/files_trashbin/files/IMG_1472.JPG.d1505157572/
data/vincent/files_encryption/keys/files_trashbin/files/IMG_1472.JPG.d1505157572/OC_DEFAULT_MODULE
data/vincent/files_encryption/keys/files_trashbin/files/IMG_1472.JPG.d1505157572/OC_DEFAULT_MODULE/vincent.shareKey
data/vincent/files_encryption/keys/files_trashbin/files/IMG_1472.JPG.d1505157572/OC_DEFAULT_MODULE/fileKey
data/vincent/files_encryption/keys/files_trashbin/files/IMG_1472.JPG.d1505157572/OC_DEFAULT_MODULE/pubShare_0a1edf68.shareKey
data/vincent/files_encryption/keys/files_trashbin/files/IMG_1472.JPG.d1505157572/OC_DEFAULT_MODULE/tingting.shareKey
What we observe:
- file was physically moved to trash but not in filecache
- file keys folder and contents was moved to trash, but only the main folder's entry was moved to trash in filecache
- file keys entry already exists in trash but at the same time still exists in the original location, with its original file id
- from looking at the file id of the deleted file keys folder in trash, the fileid is much higher so this entry was inserted, not moved. the original entry still has a lower file id so it's likely to be the correct one
What ghost has created this bogus trash key entry ?
Order of operations (as tested locally with v10.0.3RC1 and encryption):
- Webdav DELETE on remote.php/dav/...
- move2trash: file is physically moved to the trashbin
- move2trash deeper: keys folder is physically moved to trashbin
- keys folder trashbin update in filecache
- back to move2trash: trashstorage cache updater rename of original file
Ideas to explore:
-
this is the new DAV endpoint that sets up more than necessary on delete: implicit scan of the keys during deletion ??
-
did a cron run at this time and somehow triggered a scan ? (background scan on size=-1 folders?) => seems not, could not reproduce with local breakpoint / sleep
-
it's the parallel DELETE that caused some implicit rescans ? => not reproducible locally, but could still be that
- with a sleep before renaming keys I get a mysql deadlock
-
it's not getstoragestats as there was no such call around this
-
parent "files_trashbin/files" has been recreated in a haste after emptying trashbin ?? (I did empty the trashbin before the deletion) => likely unrelated
Activity
PVince81 commentedon Sep 11, 2017
Note, this is not an "upsert" like issue. There is clearly some process that somehow has inserted the key folder entry in the filecache before the code from the deletion could do it.
I suspect some background scanner or some other process that scanned the encryption folder for keys.
PVince81 commentedon Sep 12, 2017
One potential bug I see is that it seems the background scanner (in cron) is scanning any entry that has size=-1 regardless where it is in the cash, even if it's on the home storage outside of "files/". I have observed already that encryption keys are not always stored properly in oc_filecache and running the background scan makes these appear. Since they are outside of "files/" I assume the background scanner is scanning there.
Now maybe there's a race condition where it is possible for the unscanned encryption key folders (size=-1) to be partially moved to trash on-disk but not yet in the file cache, and the background scanner when running decides to scan this folder because it finds a parent entry with size=-1. This would explain why the extra encryption folder entry has been created.
I'm now trying to find a way to reproduce this theory by putting
sleepcalls in specific locations.In the end I think we'll need to fix the background scanner to be limited to "files/" when dealing with the home storage. I'd still like to have a reproducible case to be able to confirm that this is indeed the problem and that the fix resolves this.
PVince81 commentedon Sep 12, 2017
Note: the bogus additional entry has size=-1 in my DB but the other key entries didn't, so this means they were scanned already previously. The question so far is what folder would need to have size=-1 to be rescanned.
PVince81 commentedon Sep 12, 2017
Uh oh, it looks like it's even more complex. This might mean that I'm really unlucky with race conditions...
I have stepped through a single DELETE operation and observed the contents of the database.
The order is as follows:
Now what I observed is that directly after step 5, the database looked like this:
As you can see, the folder "files_encryption/keys/files_trashbin/files" has a size of -1.
Now for this one deletion it isn't that bad because we already moved the keys to trash. Running
cron.phpat this stage would just adjust the sizes and also find the other keys that weren't in oc_filecache in the first place.The deletion succeeds.
But now, with this knowledge, imagine what happens with a parallel delete and spray some cron background scan magic in the mix. If we go through the stages above and stop after step 5), let's call this one delete A. Now have a parallel delete for another file B that stops at step 4). Our database now has "files_encryption/keys/files_trashbin/files" entry with a size of -1, but also there's a deletion process for file B that has moved its keys folder physically but hasn't updated the filecache yet. Now start cron.php and have the background scanner run. The background scanner sees that "files_encryption/keys/files_trashbin/files" has a size of -1 so it rescans it, and finds the keys from B that are on disk but not in-filecache. 💥 we have a new filecache entry for the keys. Once deletion for B continues, it will try and update the filecache by moving the keys entries, but can't, because this one already exists! => integrity constraint violation.
This is still theoretical but still possible. I'll try and reproduce it with some sleep magic... Stay tuned.
PVince81 commentedon Sep 12, 2017
Ah, and usually the scanner sets scan locks but such locks are limited to the "files/" folder. So the race condition above cannot be caught by locks as there is no lock on the "files_encryption" folder...
PVince81 commentedon Sep 12, 2017
Could not reproduce the issue so far.
I do observe the "size=-1" after a single deletion.
It seems that the steps so far are as follows:
From here, I need to find what step 3 is. It likely involves deleting another file but having it sleep between moving keys on FS and moving keys in filecache. My repeated local attempts have failed. Need to look deeper to find out why.
PVince81 commentedon Sep 12, 2017
Found improved but more complex steps:
occ app:enable encryptionocc encryption:enableocc encryption:select-encryption-type user-keys -yupdate oc_jobs set last_run=0,last_checked=0,reserved_at=0;update oc_jobs set last_run=0,last_checked=0,reserved_at=0;Sleep Patch:
The patch is for pausing at the exact moment where the cache update started and the move is done.
This is important because the cache update usually checks if the target exists and deletes it first. Here we put the sleep just after that check but before the actual moving of cache entries.
Result:
PVince81 commentedon Sep 12, 2017
PVince81 commentedon Sep 12, 2017
Fix is here: #28987
lock commentedon Aug 1, 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.