Random "503" errors

Nextcloud version (eg, 20.0.5): 20.0.8.1
Operating system and version (eg, Ubuntu 20.04): Debian Buster
Apache or nginx version (eg, Apache 2.4.25): 2.4.38
PHP version (eg, 7.4): 7.4.14

The issue you are facing:
Random “503” errors when accessing files that seem to take care of themselves after a while.

Is this the first time you’ve seen this error? (Y/N): Y

The output of your Nextcloud log in Admin > Logging:

{"reqId":"TofWtFe7Ln3W0Jcqecy2","level":3,"time":"2021-03-30T08:39:19+00:00","remoteAddr":"192.168.178.104","user":"user_m","app":"PHP","method":"GET","url":"/remote.php/dav/files/user_m/Art/REDACTED%202/Units/REDACTED/Android%20REDACTED/source/REDACTED.fbx","message":{"Exception":"Error","Message":"fopen(/var/www/html/nextcloud/data/REDACTED/files/Departments/Art/REDACTED 2/Units/REDACTED/Android REDACTED/source/REDACTED.fbx): failed to open stream: Permission denied at /var/www/html/nextcloud/lib/private/Files/Storage/Local.php#355","Code":0,"Trace":[{"function":"onError","class":"OC\\Log\\ErrorHandler","type":"::"},

{"file":"/var/www/html/nextcloud/lib/private/Files/Storage/Local.php","line":355,"function":"fopen"},{"file":"/var/www/html/nextcloud/lib/private/Files/Storage/Wrapper/Quota.php","line":160,"function":"fopen","class":"OC\\Files\\Storage\\Local","type":"->"},

{"file":"/var/www/html/nextcloud/lib/private/Files/Storage/Wrapper/Wrapper.php","line":300,"function":"fopen","class":"OC\\Files\\Storage\\Wrapper\\Quota","type":"->"},

{"file":"/var/www/html/nextcloud/apps/files_accesscontrol/lib/StorageWrapper.php","line":325,"function":"fopen","class":"OC\\Files\\Storage\\Wrapper\\Wrapper","type":"->"},

{"file":"/var/www/html/nextcloud/apps/files_sharing/lib/SharedStorage.php","line":296,"function":"fopen","class":"OCA\\FilesAccessControl\\StorageWrapper","type":"->"},

{"file":"/var/www/html/nextcloud/lib/private/Files/Storage/Wrapper/Wrapper.php","line":300,"function":"fopen","class":"OCA\\Files_Sharing\\SharedStorage","type":"->"},

{"file":"/var/www/html/nextcloud/lib/private/Files/View.php","line":1165,"function":"fopen","class":"OC\\Files\\Storage\\Wrapper\\Wrapper","type":"->"},

{"file":"/var/www/html/nextcloud/lib/private/Files/View.php","line":1001,"function":"basicOperation","class":"OC\\Files\\View","type":"->"},{"file":"/var/www/html/nextcloud/apps/dav/lib/Connector/Sabre/File.php","line":434,"function":"fopen","class":"OC\\Files\\View","type":"->"},

{"file":"/var/www/html/nextcloud/3rdparty/sabre/dav/lib/DAV/CorePlugin.php","line":90,"function":"get","class":"OCA\\DAV\\Connector\\Sabre\\File","type":"->"},

{"file":"/var/www/html/nextcloud/3rdparty/sabre/event/lib/WildcardEmitterTrait.php","line":89,"function":"httpGet","class":"Sabre\\DAV\\CorePlugin","type":"->"},

{"file":"/var/www/html/nextcloud/3rdparty/sabre/dav/lib/DAV/Server.php","line":474,"function":"emit","class":"Sabre\\DAV\\Server","type":"->"},

{"file":"/var/www/html/nextcloud/3rdparty/sabre/dav/lib/DAV/Server.php","line":251,"function":"invokeMethod","class":"Sabre\\DAV\\Server","type":"->"},

{"file":"/var/www/html/nextcloud/3rdparty/sabre/dav/lib/DAV/Server.php","line":319,"function":"start","class":"Sabre\\DAV\\Server","type":"->"},{"file":"/var/www/html/nextcloud/apps/dav/lib/Server.php","line":332,"function":"exec","class":"Sabre\\DAV\\Server","type":"->"},{"file":"/var/www/html/nextcloud/apps/dav/appinfo/v2/remote.php","line":35,"function":"exec","class":"OCA\\DAV\\Server","type":"->"},{"file":"/var/www/html/nextcloud/remote.php","line":167,"args":["/var/www/html/nextcloud/apps/dav/appinfo/v2/remote.php"],"function":"require_once"}],"File":"/var/www/html/nextcloud/lib/private/Log/ErrorHandler.php","Line":91,"CustomMessage":"--"},"userAgent":"Mozilla/5.0 (Windows) mirall/3.1.3stable-Win64 (build 20210218) (Nextcloud)","version":"20.0.8.1","id":"6062e932b61f1"}

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

<?php
$CONFIG = array (
  'memcache.distributed' => '\\OC\\Memcache\\Redis',
  'redis' => 
  array (
    'host' => '127.0.0.1',
    'port' => 6379,
    'dbindex' => 0,
    'password' => REDACTED,
    'timeout' => 1.5,
  ),
  'instanceid' => REDACTED,
  'passwordsalt' => REDACTED,
  'secret' => REDACTED,
  'trusted_domains' => 
  array (
    0 => 'nextcloud.local.REDACTED',
    1 => '127.0.0.1',
    2 => 'REDACTED',
    3 => '192.168.178.32',
  ),
  'datadirectory' => '/var/www/html/nextcloud/data',
  'dbtype' => 'mysql',
  'version' => '20.0.8.1',
  'overwrite.cli.url' => 'http://nextcloud.local.REDACTED',
  'dbname' => 'nc_db',
  'dbhost' => 'localhost',
  'dbport' => '',
  'dbtableprefix' => 'oc_',
  'mysql.utf8mb4' => true,
  'dbuser' => REDACTED,
  'dbpassword' => REDACTED,
  'installed' => true,
  'mail_smtpmode' => 'smtp',
  'mail_smtphost' => 'mx10.REDACTED',
  'mail_sendmailmode' => 'smtp',
  'mail_smtpport' => '25',
  'onlyoffice' => 
  array (
    'verify_peer_off' => true,
  ),
  'allow_local_remote_servers' => true,
  'maintenance' => false,
  'theme' => '',
  'loglevel' => 2,
);

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

192.168.178.104 - user_m [30/Mar/2021:10:39:19 +0200] "GET /remote.php/dav/files/user_m/Art/REDACTED%202/Units/REDACTED/Android%20REDACTED/source/REDACTED.fbx HTTP/1.1" 503 782

The error doesn’t remain - after a period of time, the file finally downloads.

I have noticed that this doesn’t affect newly created files as one shoud expect, but files that have been there for days.

Here’s another error message that reulted in a 503 error:

{"reqId":"QC2IkE43gCBYtjC6524Q","level":3,"time":"2021-04-06T09:57:23+00:00","remoteAddr":"192.168.178.111","user":"REDACTED_USER","app":"PHP","method":"GET","url":"/remote.php/dav/files/REDACTED_USER/HR/Freelancing/FOLDERNAME_WITH_UMLAUT_AND_SPACE/2021/Art/REDACTED/REDACTED%208/REDACTED_Invoice_REDACTED_8.pdf","message":{"Exception":"Error","Message":"fopen(/var/www/html/nextcloud/data/ORIGINAL_FILE_OWNER/files/Departments/HR/Freelancing/FOLDERNAME_WITH_UMLAUT_AND_SPACE/2021/Art/REDACTED/REDACTED 8/REDACTED_Invoice_REDACTED_8.pdf): failed to open stream: Permission denied at /var/www/html/nextcloud/lib/private/Files/Storage/Local.php#355","Code":0,"Trace":[{"function":"onError","class":"OC\\Log\\ErrorHandler","type":"::"},{"file":"/var/www/html/nextcloud/lib/private/Files/Storage/Local.php","line":355,"function":"fopen"},{"file":"/var/www/html/nextcloud/lib/private/Files/Storage/Wrapper/Quota.php","line":160,"function":"fopen","class":"OC\\Files\\Storage\\Local","type":"->"},{"file":"/var/www/html/nextcloud/lib/private/Files/Storage/Wrapper/Wrapper.php","line":300,"function":"fopen","class":"OC\\Files\\Storage\\Wrapper\\Quota","type":"->"},{"file":"/var/www/html/nextcloud/apps/files_accesscontrol/lib/StorageWrapper.php","line":325,"function":"fopen","class":"OC\\Files\\Storage\\Wrapper\\Wrapper","type":"->"},{"file":"/var/www/html/nextcloud/apps/files_sharing/lib/SharedStorage.php","line":296,"function":"fopen","class":"OCA\\FilesAccessControl\\StorageWrapper","type":"->"},{"file":"/var/www/html/nextcloud/lib/private/Files/Storage/Wrapper/Wrapper.php","line":300,"function":"fopen","class":"OCA\\Files_Sharing\\SharedStorage","type":"->"},{"file":"/var/www/html/nextcloud/lib/private/Files/View.php","line":1165,"function":"fopen","class":"OC\\Files\\Storage\\Wrapper\\Wrapper","type":"->"},{"file":"/var/www/html/nextcloud/lib/private/Files/View.php","line":1001,"function":"basicOperation","class":"OC\\Files\\View","type":"->"},{"file":"/var/www/html/nextcloud/apps/dav/lib/Connector/Sabre/File.php","line":434,"function":"fopen","class":"OC\\Files\\View","type":"->"},{"file":"/var/www/html/nextcloud/3rdparty/sabre/dav/lib/DAV/CorePlugin.php","line":90,"function":"get","class":"OCA\\DAV\\Connector\\Sabre\\File","type":"->"},{"file":"/var/www/html/nextcloud/3rdparty/sabre/event/lib/WildcardEmitterTrait.php","line":89,"function":"httpGet","class":"Sabre\\DAV\\CorePlugin","type":"->"},{"file":"/var/www/html/nextcloud/3rdparty/sabre/dav/lib/DAV/Server.php","line":474,"function":"emit","class":"Sabre\\DAV\\Server","type":"->"},{"file":"/var/www/html/nextcloud/3rdparty/sabre/dav/lib/DAV/Server.php","line":251,"function":"invokeMethod","class":"Sabre\\DAV\\Server","type":"->"},{"file":"/var/www/html/nextcloud/3rdparty/sabre/dav/lib/DAV/Server.php","line":319,"function":"start","class":"Sabre\\DAV\\Server","type":"->"},{"file":"/var/www/html/nextcloud/apps/dav/lib/Server.php","line":332,"function":"exec","class":"Sabre\\DAV\\Server","type":"->"},{"file":"/var/www/html/nextcloud/apps/dav/appinfo/v2/remote.php","line":35,"function":"exec","class":"OCA\\DAV\\Server","type":"->"},{"file":"/var/www/html/nextcloud/remote.php","line":167,"args":["/var/www/html/nextcloud/apps/dav/appinfo/v2/remote.php"],"function":"require_once"}],"File":"/var/www/html/nextcloud/lib/private/Log/ErrorHandler.php","Line":91,"CustomMessage":"--"},"userAgent":"Mozilla/5.0 (Windows) mirall/3.1.3stable-Win64 (build 20210218) (Nextcloud)","version":"20.0.8.1"}
{"reqId":"QC2IkE43gCBYtjC6524Q","level":4,"time":"2021-04-06T09:57:23+00:00","remoteAddr":"192.168.178.111","user":"REDACTED_USER","app":"webdav","method":"GET","url":"/remote.php/dav/files/REDACTED_USER/HR/Freelancing/FOLDERNAME_WITH_UMLAUT_AND_SPACE/2021/Art/REDACTED/REDACTED%208/REDACTED_Invoice_REDACTED_8.pdf","message":{"Exception":"Sabre\\DAV\\Exception\\ServiceUnavailable","Message":"Could not open file","Code":0,"Trace":[{"file":"/var/www/html/nextcloud/3rdparty/sabre/dav/lib/DAV/CorePlugin.php","line":90,"function":"get","class":"OCA\\DAV\\Connector\\Sabre\\File","type":"->"},{"file":"/var/www/html/nextcloud/3rdparty/sabre/event/lib/WildcardEmitterTrait.php","line":89,"function":"httpGet","class":"Sabre\\DAV\\CorePlugin","type":"->"},{"file":"/var/www/html/nextcloud/3rdparty/sabre/dav/lib/DAV/Server.php","line":474,"function":"emit","class":"Sabre\\DAV\\Server","type":"->"},{"file":"/var/www/html/nextcloud/3rdparty/sabre/dav/lib/DAV/Server.php","line":251,"function":"invokeMethod","class":"Sabre\\DAV\\Server","type":"->"},{"file":"/var/www/html/nextcloud/3rdparty/sabre/dav/lib/DAV/Server.php","line":319,"function":"start","class":"Sabre\\DAV\\Server","type":"->"},{"file":"/var/www/html/nextcloud/apps/dav/lib/Server.php","line":332,"function":"exec","class":"Sabre\\DAV\\Server","type":"->"},{"file":"/var/www/html/nextcloud/apps/dav/appinfo/v2/remote.php","line":35,"function":"exec","class":"OCA\\DAV\\Server","type":"->"},{"file":"/var/www/html/nextcloud/remote.php","line":167,"args":["/var/www/html/nextcloud/apps/dav/appinfo/v2/remote.php"],"function":"require_once"}],"File":"/var/www/html/nextcloud/apps/dav/lib/Connector/Sabre/File.php","Line":439,"CustomMessage":"--"},"userAgent":"Mozilla/5.0 (Windows) mirall/3.1.3stable-Win64 (build 20210218) (Nextcloud)","version":"20.0.8.1"}

What strikes me is this:

failed to open stream: Permission denied at /var/www/html/nextcloud/lib/private/Files/Storage/Local.php#355

The file is present, file and directory rights match (rw or rwx respectively for user “www-data”), it has been created a week ago and apparently not changed since.

The error appears when syncing from a workstation with the NC client.