Skip to content

Deleting many files with the same name causes trashbin database error (integrity contstraint violation, duplicate entry) #17213

@MarcelWaldvogel

Description

@MarcelWaldvogel

Steps to reproduce

  1. Have the desktop sync client on a machine and the trashbin app on the server
  2. In the synced directory, have many files with the same name but in different directories (e.g. using find . -type d -exec touch {}/_TEST_FILE_ \;)
  3. Wait for these files to be synced to the server
  4. Delete all of these files on the client within a short period of time (e.g. using find . -name _TEST_FILE_ -exec rm {} \;)

Expected behaviour

All the files are moved to the trashbin with no errors

Actual behaviour

  • Several errors appear in the sync client activity log: Server replied "500 Server Error" to "DELETE https://[…]/_TEST_FILE_"
  • Nextcloud server log shows many of these messages:
[webdav] Fatal: Doctrine\DBAL\Exception\UniqueConstraintViolationException: An exception occurred while executing 'UPDATE `oc_filecache` SET `storage` = ?, `path` = ?, `path_hash` = ?, `name` = ?, `parent` = ? WHERE `fileid` = ?' with params [1, "files_trashbin\/files\/_TEST_FILE_.d1568906728", "2483968b8cffabc109c268695206d8c2", "_TEST_FILE_.d1568906728", 1451947, 1476273]:

SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '1-2483968b8cffabc109c268695206d8c2' for key 'fs_storage_path_hash' at <<closure>>

 0. /var/www/nextcloud/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/DBALException.php line 184
    Doctrine\DBAL\Driver\AbstractMySQLDriver->convertException("An exception oc ... '", Doctrine\DBAL\Dr ... ]})
 1. /var/www/nextcloud/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/DBALException.php line 158
    Doctrine\DBAL\DBALException::wrapException(Doctrine\DBAL\Driver\PDOMySql\Driver {}, Doctrine\DBAL\Dr ... ]}, "An exception oc ... '")
 2. /var/www/nextcloud/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/Connection.php line 938
    Doctrine\DBAL\DBALException::driverExceptionDuringQuery(Doctrine\DBAL\Driver\PDOMySql\Driver {}, Doctrine\DBAL\Dr ... ]}, "UPDATE `oc_file ... ?", {1: 1,2: "files_ ... 3})
 3. /var/www/nextcloud/lib/private/DB/Connection.php line 195
    Doctrine\DBAL\Connection->executeQuery("UPDATE `oc_file ... ?", [1,"files_trashb ... 3], [], null)
 4. /var/www/nextcloud/lib/private/Files/Cache/Cache.php line 579
    OC\DB\Connection->executeQuery("UPDATE `oc_file ... ?", [1,"files_trashb ... 3])
 5. /var/www/nextcloud/lib/private/Files/Cache/Cache.php line 509
    OC\Files\Cache\Cache->moveFromCache(OC\Files\Cache\HomeCache {}, "files/[…]/_TEST_FILE_", "files_trashbin/ ... 8")
 6. /var/www/nextcloud/lib/private/Files/Cache/Updater.php line 196
    OC\Files\Cache\Cache->move("files/[…]/_TEST_FILE_", "files_trashbin/ ... 8")
 7. /var/www/nextcloud/apps/files_trashbin/lib/Trashbin.php line 273
    OC\Files\Cache\Updater->renameFromStorage(OCA\Files_Trashb ... }}, "files/[…]/_TEST_FILE_", "files_trashbin/ ... 8")
 8. /var/www/nextcloud/apps/files_trashbin/lib/Trash/LegacyTrashBackend.php line 107
    OCA\Files_Trashbin\Trashbin::move2trash("[…]/_TEST_FILE_")
 9. /var/www/nextcloud/apps/files_trashbin/lib/Trash/TrashManager.php line 103
    OCA\Files_Trashbin\Trash\LegacyTrashBackend->moveToTrash(OCA\Files_Trashb ... }}, "files/[…]/_TEST_FILE_")
10. /var/www/nextcloud/apps/files_trashbin/lib/Storage.php line 186
    OCA\Files_Trashbin\Trash\TrashManager->moveToTrash(OCA\Files_Trashb ... }}, "files/[…]/_TEST_FILE_")
11. /var/www/nextcloud/apps/files_trashbin/lib/Storage.php line 98
    OCA\Files_Trashbin\Storage->doDelete("files/[…]/_TEST_FILE_", "unlink")
12. /var/www/nextcloud/lib/private/Files/View.php line 1160
    OCA\Files_Trashbin\Storage->unlink("files/[…]/_TEST_FILE_")
13. /var/www/nextcloud/lib/private/Files/View.php line 716
    OC\Files\View->basicOperation("unlink", "/[…]/_TEST_FILE_", ["delete"])
14. /var/www/nextcloud/apps/dav/lib/Connector/Sabre/File.php line 422
    OC\Files\View->unlink("/[…]/_TEST_FILE_")
15. /var/www/nextcloud/3rdparty/sabre/dav/lib/DAV/Tree.php line 179
    OCA\DAV\Connector\Sabre\File->delete()
16. /var/www/nextcloud/3rdparty/sabre/dav/lib/DAV/CorePlugin.php line 287
    Sabre\DAV\Tree->delete("files/marcel/Me ... _")
17. <<closure>>
    Sabre\DAV\CorePlugin->httpDelete(Sabre\HTTP\Reque ... "}, Sabre\HTTP\Response {})
18. /var/www/nextcloud/3rdparty/sabre/event/lib/EventEmitterTrait.php line 105
    undefinedundefinedcall_user_func_array([Sabre\DAV\CorePlugin {},"httpDelete"], [Sabre\HTTP\Requ ... }])
19. /var/www/nextcloud/3rdparty/sabre/dav/lib/DAV/Server.php line 479
    Sabre\Event\EventEmitter->emit("method:DELETE", [Sabre\HTTP\Requ ... }])
20. /var/www/nextcloud/3rdparty/sabre/dav/lib/DAV/Server.php line 254
    Sabre\DAV\Server->invokeMethod(Sabre\HTTP\Reque ... "}, Sabre\HTTP\Response {})
21. /var/www/nextcloud/apps/dav/lib/Server.php line 316
    Sabre\DAV\Server->exec()
22. /var/www/nextcloud/apps/dav/appinfo/v2/remote.php line 35
    OCA\DAV\Server->exec()
23. /var/www/nextcloud/remote.php line 163
    undefinedundefinedrequire_once("/var/www/nextcl ... p")

DELETE /remote.php/dav/files/marcel/[…]/_TEST_FILE_
from 1.2.3.4 by marcel at 2019-09-19T15:25:28+00:00

It seems that — within one second — only one file with the same name may be moved into the trashbin. Appending .d<current second> to the file name does not provide enough uniqueness.

Server configuration

Nextcloud version: 16.04

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions