User files corrupted, files:scan shows error

Nextcloud version: 14.0.3 (installed via snap)
Operating system and version: Ubuntu 18.04
Apache or nginx version: 1.14.0
PHP version: 7.1 (according to nextcloud-snap readme)

The issue you are facing:

I am hosting a small Nextcloud instance via Snap for my family. Now one of the users encountered problems, files are missing and uploads are not working.

I ran the nextcloud.occ command to rescan files, thinking that might fix it. But it actually threw an error for that user. Other users did not show any errors.

$ sudo nextcloud.occ files:scan --all

Scanning files for 5 users
Starting scan for user 1 out of 5 (f)
Starting scan for user 2 out of 5 (k)
Exception during scan: Undefined variable: response
#0 /snap/nextcloud/9448/htdocs/lib/private/Files/Storage/DAV.php(283): OCA\Files\Command\Scan->exceptionErrorHandler(8, 'Undefined varia...', '/snap/nextcloud...', 283, Array)
#1 /snap/nextcloud/9448/htdocs/apps/files_sharing/lib/External/Storage.php(355): OC\Files\Storage\DAV->propfind('')                                                                   
#2 /snap/nextcloud/9448/htdocs/lib/private/Files/Storage/Common.php(666): OCA\Files_Sharing\External\Storage->getPermissions('')                                                      
#3 /snap/nextcloud/9448/htdocs/lib/private/Files/Storage/Wrapper/Wrapper.php(581): OC\Files\Storage\Common->getMetaData('')                                                           
#4 /snap/nextcloud/9448/htdocs/lib/private/Files/Storage/Wrapper/Availability.php(463): OC\Files\Storage\Wrapper\Wrapper->getMetaData('')                                             
#5 /snap/nextcloud/9448/htdocs/lib/private/Files/Storage/Wrapper/Wrapper.php(581): OC\Files\Storage\Wrapper\Availability->getMetaData('')                                             
#6 /snap/nextcloud/9448/htdocs/lib/private/Files/Cache/Scanner.php(112): OC\Files\Storage\Wrapper\Wrapper->getMetaData('')                                                            
#7 /snap/nextcloud/9448/htdocs/lib/private/Files/Cache/Scanner.php(150): OC\Files\Cache\Scanner->getData('')                                                                          
#8 /snap/nextcloud/9448/htdocs/apps/files_sharing/lib/External/Scanner.php(62): OC\Files\Cache\Scanner->scanFile('', true)                                                            
#9 /snap/nextcloud/9448/htdocs/lib/private/Files/Cache/Scanner.php(336): OCA\Files_Sharing\External\Scanner->scanFile('', true, -1, NULL, true)                                       
#10 /snap/nextcloud/9448/htdocs/apps/files_sharing/lib/External/Scanner.php(41): OC\Files\Cache\Scanner->scan('', true, true, true)                                                   
#11 /snap/nextcloud/9448/htdocs/lib/private/Files/Utils/Scanner.php(245): OCA\Files_Sharing\External\Scanner->scan('', true, 3)                                                       
#12 /snap/nextcloud/9448/htdocs/apps/files/lib/Command/Scan.php(172): OC\Files\Utils\Scanner->scan('/k', true, NULL)                                                               
#13 /snap/nextcloud/9448/htdocs/apps/files/lib/Command/Scan.php(249): OCA\Files\Command\Scan->scanFiles('k', '/k', false, Object(Symfony\Component\Console\Output\ConsoleOutput), false, true, false)                                                                                                                                                                 
#14 /snap/nextcloud/9448/htdocs/3rdparty/symfony/console/Command/Command.php(251): OCA\Files\Command\Scan->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))                                                                                                                                               
#15 /snap/nextcloud/9448/htdocs/core/Command/Base.php(162): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))                                                                                                                                                       
#16 /snap/nextcloud/9448/htdocs/3rdparty/symfony/console/Application.php(946): OC\Core\Command\Base->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))                                                                                                                                                         
#17 /snap/nextcloud/9448/htdocs/3rdparty/symfony/console/Application.php(248): Symfony\Component\Console\Application->doRunCommand(Object(OCA\Files\Command\Scan), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))                                                                                               
#18 /snap/nextcloud/9448/htdocs/3rdparty/symfony/console/Application.php(148): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))                                                                                                                                      
#19 /snap/nextcloud/9448/htdocs/lib/private/Console/Application.php(213): Symfony\Component\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))                                                                                                                                             
#20 /snap/nextcloud/9448/htdocs/console.php(96): OC\Console\Application->run()                                                                                                        
#21 /snap/nextcloud/9448/htdocs/occ(11): require_once('/snap/nextcloud...')                                                                                                           
#22 {main}                                                                                                                                                                            
Starting scan for user 3 out of 5 (ma)
Starting scan for user 4 out of 5 (mi)
Starting scan for user 5 out of 5 (s)

+---------+-------+--------------+
| Folders | Files | Elapsed time |
+---------+-------+--------------+
| 2183    | 61765 | 00:02:25     |
+---------+-------+--------------+

Is this the first time you’ve seen this error? Yes

Steps to replicate it:

unknown

The output of your Nextcloud log in Admin > Logging:

{"reqId":"d61T0SfjYT8a7jVQbFtl","level":3,"time":"2018-11-14T11:37:53+00:00","remoteAddr":"127.0.0.1","user":"k","app":"PHP","method":"PROPFIND","url":"\/remote.php\/webdav\/k%20Fotos\/","message":"Undefined variable: response at \/snap\/nextcloud\/9448\/htdocs\/lib\/private\/Files\/Storage\/DAV.php#283","userAgent":"Mozilla\/5.0 (Android) Nextcloud-android\/3.3.2","version":"14.0.3.0"}
{"reqId":"N9O42TwDXgHyWAyPZOB8","level":3,"time":"2018-11-14T11:37:53+00:00","remoteAddr":"127.0.0.1","user":"k","app":"PHP","method":"GET","url":"\/ocs\/v2.php\/apps\/files_sharing\/api\/v1\/shares?path=%2Fk+Fotos%2F&reshares=true&subfiles=true","message":"Undefined variable: response at \/snap\/nextcloud\/9448\/htdocs\/lib\/private\/Files\/Storage\/DAV.php#283","userAgent":"Mozilla\/5.0 (Android) ownCloud-android\/3.3.2","version":"14.0.3.0"}
{"reqId":"qICgzPi1LQ0ZtJvjROsl","level":3,"time":"2018-11-14T11:37:53+00:00","remoteAddr":"127.0.0.1","user":"k","app":"PHP","method":"PROPFIND","url":"\/remote.php\/webdav\/k%20Fotos\/2018-07_Cartagena%2C%20Kolumbien\/","message":"Undefined variable: response at \/snap\/nextcloud\/9448\/htdocs\/lib\/private\/Files\/Storage\/DAV.php#283","userAgent":"Mozilla\/5.0 (Android) Nextcloud-android\/3.3.2","version":"14.0.3.0"}
{"reqId":"0fduRka5sEsXOgyt59EC","level":3,"time":"2018-11-14T11:37:54+00:00","remoteAddr":"127.0.0.1","user":"k","app":"PHP","method":"PROPFIND","url":"\/remote.php\/webdav\/k%20Fotos\/2018-07_Cartagena%2C%20Kolumbien\/","message":"Undefined variable: response at \/snap\/nextcloud\/9448\/htdocs\/lib\/private\/Files\/Storage\/DAV.php#283","userAgent":"Mozilla\/5.0 (Android) Nextcloud-android\/3.3.2","version":"14.0.3.0"}
{"reqId":"VBDmvglbS5lSuTRoSjSH","level":3,"time":"2018-11-14T11:37:56+00:00","remoteAddr":"127.0.0.1","user":"k","app":"PHP","method":"PROPFIND","url":"\/remote.php\/webdav\/k%20Fotos\/2018-07_Cartagena%2C%20Kolumbien\/","message":"Undefined variable: response at \/snap\/nextcloud\/9448\/htdocs\/lib\/private\/Files\/Storage\/DAV.php#283","userAgent":"Mozilla\/5.0 (Android) Nextcloud-android\/3.3.2","version":"14.0.3.0"}

This is just an excerpt, there are many more lines like this. I can send the full log by private message.

The output of your config.php file in /path/to/nextcloud (make sure you remove any identifiable information!):

<?php
$CONFIG = array (
  'apps_paths' => 
  array (
    0 => 
    array (
      'path' => '/snap/nextcloud/current/htdocs/apps',
      'url' => '/apps',
      'writable' => false,
    ),
    1 => 
    array (
      'path' => '/var/snap/nextcloud/current/nextcloud/extra-apps',
      'url' => '/extra-apps',
      'writable' => true,
    ),
  ),
  'supportedDatabases' => 
  array (
    0 => 'mysql',
  ),
  'memcache.locking' => '\\OC\\Memcache\\Redis',
  'memcache.local' => '\\OC\\Memcache\\Redis',
  'redis' => 
  array (
    'host' => '/tmp/sockets/redis.sock',
    'port' => 0,
  ),
  'passwordsalt' => 'xxx',
  'secret' => 'xxx',
  'trusted_domains' => 
  array (
    0 => 'localhost',
    2 => 'nextcloud.nutomic.com',
  ),
  'datadirectory' => '/media/storage-nextcloud/',
  'overwrite.cli.url' => 'https:/mydomain.com/',
  'dbtype' => 'mysql',
  'version' => '14.0.3.0',
  'dbname' => 'nextcloud',
  'dbhost' => 'localhost:/tmp/sockets/mysql.sock',
  'dbport' => '',
  'dbtableprefix' => 'oc_',
  'mysql.utf8mb4' => true,
  'dbuser' => 'nextcloud',
  'dbpassword' => 'xxx',
  'installed' => true,
  'overwritehost' => 'mydomain.com',
  'overwritewebroot' => '/',
  'mail_smtpmode' => 'smtp',
  'mail_smtpauthtype' => 'PLAIN',
  'loglevel' => 2,
  'maintenance' => false,
  'htaccess.RewriteBase' => '/',
  'mail_domain' => 'mydomain.com',
  'mail_from_address' => 'info',
  'allow_user_to_change_display_name' => false,
  'instanceid' => 'ock64s3eh7m5',
  'preview_max_y' => 2048,
  'preview_max_x' => 2048,
  'trashbin_retention_obligation' => 'auto, 60',
  'versions_retention_obligation' => 'auto, 60',
  'mail_smtphost' => 'localhost',
  'mail_smtpport' => '587',
);

The output of your Apache/nginx/system log in /var/log/____:

2018/11/13 18:42:41 [error] 16131#16131: *18519 upstream prematurely closed connection while reading upstream, client: 87.171.41.4, server: nextcloud.nutomic.com, request: "GET /remote.php/webdav/k%20Fotos/2018-05_h/Landschaften/DSC04691.JPG HTTP/1.1", upstream: "http://127.0.0.1:81/remote.php/webdav/k%20Fotos/2018-05_h/Landschaften/DSC04691.JPG", host: "nextcloud.nutomic.com"
2018/11/13 18:45:59 [error] 16131#16131: *19296 upstream prematurely closed connection while reading upstream, client: 87.171.41.4, server: nextcloud.nutomic.com, request: "GET /remote.php/webdav/k%20Fotos/2018-05_h/Landschaften/DSC04691.JPG HTTP/1.1", upstream: "http://127.0.0.1:81/remote.php/webdav/k%20Fotos/2018-05_h/Landschaften/DSC04691.JPG", host: "nextcloud.nutomic.com"
2018/11/13 18:48:20 [error] 16131#16131: *19810 upstream prematurely closed connection while reading upstream, client: 87.171.41.4, server: nextcloud.nutomic.com, request: "GET /remote.php/webdav/k%20Fotos/2018-05_h/Landschaften/DSC04691.JPG HTTP/1.1", upstream: "http://127.0.0.1:81/remote.php/webdav/k%20Fotos/2018-05_h/Landschaften/DSC04691.JPG", host: "nextcloud.nutomic.com"
2018/11/13 20:14:30 [error] 16131#16131: *22746 upstream prematurely closed connection while reading upstream, client: 87.171.41.4, server: nextcloud.nutomic.com, request: "GET /remote.php/webdav/k%20Fotos/2018-07_c%2C%k/20180622_100506.jpg HTTP/1.1", upstream: "http://127.0.0.1:81/remote.php/webdav/k%20Fotos/2018-07_c%2C%k/20180622_100506.jpg", host: "nextcloud.nutomic.com"

Again just an excerpt with affected files. And note that only one user is affected.

I did move my Nextcloud installation to a different domain recently, but I don’t that that is related to the error, because the move was a few weeks ago, and other user accounts work fine.

Okay it turns out the missing files were shared by another user, and that user unshared them. But they were still shown in the Android app. Also, it doesn’t explain why the scan command is failing.

That sounds like a Nextcloud bug. Is it something you can duplicate?

I have no idea how it happened in the first place, so I don’t know how I could even try to duplicate it.

If you install Nextcloud on your laptop, for example, and create two users, share files from one to the other, and then unshare them, can you get Nextcloud into a similar state (the snap is great for such tests)?

Not sure if this would work on a laptop, because the Android app might be related and I couldn’t connect it in that case. I don’t know if I will have time to try and reproduce it, but here’s an idea how to go about it:

  1. Have 2 user accounts A and B on the same Nextcloud instance (or you can work together with another user on the same instance)
  2. User A creates a folder with some pictures and shares it with user B (not sure which sharing settings, just try the defaults)
  3. User B browses the folder and files in the Android app
  4. User A unshares the folder again
  5. User B checks if the images are still accessible and displayable

The more I think about this, the more it seems like a bug in the Android app.