nextcloud / server

☁️ Nextcloud server, a safe home for all your data
https://nextcloud.com
GNU Affero General Public License v3.0
26.86k stars 4.01k forks source link

No logs when config file lock blocks indefinitely #35008

Open jficz opened 1 year ago

jficz commented 1 year ago

⚠️ This issue respects the following points: ⚠️

Bug description

One of the first things that happens during start is loading and locking config file(s) with flock(). If, for whatever reason, the locking mechanism at the OS level blocks indefinitely, there is no way for the user to have any idea what's actually going on without resorting to advanced debugging.

This is true for both normal operation (via fpm, mod, etc.) and for occ which makes the issue even more frustrating.

The call to the function happens before any kind of reasonable logs are displayed.

In my case config.php is located on a NFS filesystem. The reasons for the unability to acquire the lock are as of yet unknown.

Steps to reproduce

  1. config.php cannot be locked via the portable flock() function in a way that the function blocks indefinitely (or longer than upstream timeouts) 2a. open Nextcloud instance in a browser OR 2b. run php occ

Expected behavior

Some kind of unconditional trace or "step-by-step" log should be configurable to be shown even before the config is read, describing the steps taken so far. ex:

Initializing Nextcloud v24.0.6
Looking up config environment...
Config dir found at '/mnt/nfs/nextcloud/config'
Found config files '<list of *.config.php>'
Opening file <file>
Acquiring lock on <file>

at least in occ.

Installation method

Other Community project

Operating system

Other

PHP engine version

PHP 8.0

Web server

Nginx

Database engine version

PostgreSQL

Is this bug present after an update or on a fresh install?

No response

Are you using the Nextcloud Server Encryption module?

Encryption is Disabled

What user-backends are you using?

Configuration report

(occ doesn't run, see above)

List of activated Apps

see above

Nextcloud Signing status

see above

Nextcloud Logs

no logs

Additional info

No response

GuyPaddock commented 1 year ago

Related issue: If the filesystem that the configuration files are loaded from (e.g., SMB mount inside a Docker container) doesn't support file locking, the config won't load at all, and we get this error instead:

Fatal error: Uncaught Error: Call to a member function getLogger() on null in /var/www/html/cron.php:189
Stack trace:
#0 {main}
  thrown in /var/www/html/cron.php on line 189

Which is caused by:

Could not acquire a shared lock on the config file /var/www/html/config/apcu.config.php:216

Perhaps there's some way that config file locking can be disabled at admin discretion, especially on a read-only file system?

joshtrichards commented 1 year ago

There is the config_is_read_only option (https://docs.nextcloud.com/server/latest/admin_manual/configuration_server/config_sample_php_parameters.html#config-is-read-only). It may help with some, but not all of these situations since it's still expected to be togged to false again during various operations where write access is expected.