Many files are locked during scan of user folder

I have the same problem, it seems like various files got locked up.

Here is the exception I got when scanning NC for externally modified files:

Starting scan for user 2 out of 5 (Daniel)
Exception during scan: File entry could not be inserted with insertIfNotExist() but could also not be selected with getId() in order to perform an update. Please try again.
#0 /var/www/nextcloud/lib/private/Files/Cache/Cache.php(230): OC\Files\Cache\Cache->insert('files/07_AutoUp...', Array)
#1 /var/www/nextcloud/lib/private/Files/Cache/Scanner.php(292): OC\Files\Cache\Cache->put('files/07_AutoUp...', Array)
#2 /var/www/nextcloud/lib/private/Files/Cache/Scanner.php(221): OC\Files\Cache\Scanner->addToCache('files/07_AutoUp...', Array, -1)
#3 /var/www/nextcloud/lib/private/Files/Cache/Scanner.php(435): OC\Files\Cache\Scanner->scanFile('files/07_AutoUp...', 3, '2402', false, true)
#4 /var/www/nextcloud/lib/private/Files/Cache/Scanner.php(403): OC\Files\Cache\Scanner->handleChildren('files/07_AutoUp...', true, 3, '2402', true, 1493425852)
#5 /var/www/nextcloud/lib/private/Files/Cache/Scanner.php(406): OC\Files\Cache\Scanner->scanChildren('files/07_AutoUp...', true, 3, '2402', true)
#6 /var/www/nextcloud/lib/private/Files/Cache/Scanner.php(406): OC\Files\Cache\Scanner->scanChildren('files/07_AutoUp...', true, 3, '2399', true)
#7 /var/www/nextcloud/lib/private/Files/Cache/Scanner.php(406): OC\Files\Cache\Scanner->scanChildren('files', true, 3, '304', true)
#8 /var/www/nextcloud/lib/private/Files/Cache/Scanner.php(337): OC\Files\Cache\Scanner->scanChildren('', true, 3, '302', true)
#9 /var/www/nextcloud/lib/private/Files/Utils/Scanner.php(244): OC\Files\Cache\Scanner->scan('', true, 3)
#10 /var/www/nextcloud/apps/files/lib/Command/Scan.php(161): OC\Files\Utils\Scanner->scan('/Daniel')
#11 /var/www/nextcloud/apps/files/lib/Command/Scan.php(234): OCA\Files\Command\Scan->scanFiles('Daniel', '/Daniel', false, Object(Symfony\Component\Console\Output\ConsoleOutput), false)
#12 /var/www/nextcloud/3rdparty/symfony/console/Command/Command.php(264): OCA\Files\Command\Scan->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#13 /var/www/nextcloud/core/Command/Base.php(161): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#14 /var/www/nextcloud/3rdparty/symfony/console/Application.php(874): OC\Core\Command\Base->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#15 /var/www/nextcloud/3rdparty/symfony/console/Application.php(228): Symfony\Component\Console\Application->doRunCommand(Object(OCA\Files\Command\Scan), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#16 /var/www/nextcloud/3rdparty/symfony/console/Application.php(130): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#17 /var/www/nextcloud/lib/private/Console/Application.php(173): Symfony\Component\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#18 /var/www/nextcloud/console.php(90): OC\Console\Application->run()
#19 /var/www/nextcloud/occ(11): require_once('/var/www/nextcl...')
#20 {main}

The fun thing is that no problems occured when i uploaded it from my PC but when i try to sync it with my laptop I get various “file is empty, although server reported x size…” errors, but just for (I think tey are the same) those few files.

Is this on external storage? Does it work when you put Nextcloud in maintenance mode?

Do you use redis as file locking cache? What version of php and what environment do you use?

I have the same problem and a quite fresh install of Nextcloudpi (without any other modifications) on Raspi3, using an external USB HDD formatted in Btrfs.

Starting scan for user 3 out of 3 (ncp)
Exception during scan: File entry could not be inserted with insertIfNotExist() but could also not be selected with getId() in order to perform an update. Please try again.
#0 /var/www/nextcloud/lib/private/Files/Cache/Cache.php(230): OC\Files\Cache\Cache->insert('files/Dokumente...', Array)
#1 /var/www/nextcloud/lib/private/Files/Cache/Scanner.php(292): OC\Files\Cache\Cache->put('files/Dokumente...', Array)
#2 /var/www/nextcloud/lib/private/Files/Cache/Scanner.php(221): OC\Files\Cache\Scanner->addToCache('files/Dokumente...', Array, -1)
#3 /var/www/nextcloud/lib/private/Files/Cache/Scanner.php(435): OC\Files\Cache\Scanner->scanFile('files/Dokumente...', 3, '366', false, true)
#4 /var/www/nextcloud/lib/private/Files/Cache/Scanner.php(403): OC\Files\Cache\Scanner->handleChildren('files/Dokumente...', true, 3, '366', true, 0)
#5 /var/www/nextcloud/lib/private/Files/Cache/Scanner.php(406): OC\Files\Cache\Scanner->scanChildren('files/Dokumente...', true, 3, '366', true)
#6 /var/www/nextcloud/lib/private/Files/Cache/Scanner.php(406): OC\Files\Cache\Scanner->scanChildren('files', true, 3, '2', true)
#7 /var/www/nextcloud/lib/private/Files/Cache/Scanner.php(337): OC\Files\Cache\Scanner->scanChildren('', true, 3, '1', true)
#8 /var/www/nextcloud/lib/private/Files/Utils/Scanner.php(244): OC\Files\Cache\Scanner->scan('', true, 3)
#9 /var/www/nextcloud/apps/files/lib/Command/Scan.php(161): OC\Files\Utils\Scanner->scan('/ncp')
#10 /var/www/nextcloud/apps/files/lib/Command/Scan.php(234): OCA\Files\Command\Scan->scanFiles('ncp', '/ncp', false, Object(Symfony\Component\Console\Output\ConsoleOutput), false)
#11 /var/www/nextcloud/3rdparty/symfony/console/Command/Command.php(264): OCA\Files\Command\Scan->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#12 /var/www/nextcloud/core/Command/Base.php(161): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#13 /var/www/nextcloud/3rdparty/symfony/console/Application.php(874): OC\Core\Command\Base->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#14 /var/www/nextcloud/3rdparty/symfony/console/Application.php(228): Symfony\Component\Console\Application->doRunCommand(Object(OCA\Files\Command\Scan), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#15 /var/www/nextcloud/3rdparty/symfony/console/Application.php(130): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#16 /var/www/nextcloud/lib/private/Console/Application.php(173): Symfony\Component\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#17 /var/www/nextcloud/console.php(90): OC\Console\Application->run()
#18 /var/www/nextcloud/occ(11): require_once('/var/www/nextcl...')
#19 {main}

+---------+-------+--------------+
| Folders | Files | Elapsed time |
+---------+-------+--------------+
| 1378    | 36497 | 00:25:38     |
+---------+-------+--------------+

Anyone got any ideas?

bump! got same error here… after upgrade 15.0

this external storage and then all error