Internal server error when uploading and changing gridview

I just installed Nextcloud on a private Debian 11 with NGINX and MariaDB. It is connected to an external NFS server for storage.

At the moment there are two sync streams running. One from my phone (57 GB) and another one from a PC (130 GB). This works fine, until I go into the interface All Files > Photos > Random folder. Once I click “Troggle Gridview” in the upper right corner, it instantly cuts the connection with the two uploads reporting “500 Internal Server Error” in the clients. I am able to reproduce it.

The server log shows:

{"reqId":"WpRuVEvZgf2F2iUR8d69","level":3,"time":"2022-02-19T08:23:53+00:00","remoteAddr":"10.x.x.x","user":"username","app":"core","method":"GET","url":"/nextcloud/core/preview?fileId=48389&c=66c6f84d8ede56bd977696f339dec765&x=250&y=250&forceIcon=0&a=0","message":"Failed to connect to the database: An exception occurred in the driver: SQLSTATE[HY000] [2002] Connection refused","userAgent":"Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:97.0) Gecko/20100101 Firefox/97.0","version":"23.0.0.10","exception":{"Exception":"Doctrine\\DBAL\\Exception","Message":"Failed to connect to the database: An exception occurred in the driver: SQLSTATE[HY000] [2002] Connection refused","Code":2002,"Trace":[{"file":"/var/www/html/nextcloud/3rdparty/doctrine/dbal/src/Connection.php","line":1519,"function":"connect","class":"OC\\DB\\Connection","type":"->"},{"file":"/var/www/html/nextcloud/3rdparty/doctrine/dbal/src/Connection.php","line":1041,"function":"getWrappedConnection","class":"Doctrine\\DBAL\\Connection","type":"->"},{"file":"/var/www/html/nextcloud/lib/private/DB/Connection.php","line":236,"function":"executeQuery","class":"Doctrine\\DBAL\\Connection","type":"->"},{"file":"/var/www/html/nextcloud/3rdparty/doctrine/dbal/src/Query/QueryBuilder.php","line":345,"function":"executeQuery","class":"OC\\DB\\Connection","type":"->"},{"file":"/var/www/html/nextcloud/lib/private/DB/QueryBuilder/QueryBuilder.php","line":287,"function":"execute","class":"Doctrine\\DBAL\\Query\\QueryBuilder","type":"->"},{"file":"/var/www/html/nextcloud/lib/private/Files/Cache/Cache.php","line":164,"function":"execute","class":"OC\\DB\\QueryBuilder\\QueryBuilder","type":"->"},{"file":"/var/www/html/nextcloud/lib/private/Files/View.php","line":1338,"function":"get","class":"OC\\Files\\Cache\\Cache","type":"->"},{"file":"/var/www/html/nextcloud/lib/private/Files/View.php","line":1393,"function":"getCacheEntry","class":"OC\\Files\\View","type":"->"},{"file":"/var/www/html/nextcloud/lib/private/Files/Node/Root.php","line":200,"function":"getFileInfo","class":"OC\\Files\\View","type":"->"},{"function":"get","class":"OC\\Files\\Node\\Root","type":"->"},{"file":"/var/www/html/nextcloud/lib/private/Files/Node/LazyFolder.php","line":65,"function":"call_user_func_array"},{"file":"/var/www/html/nextcloud/lib/private/Files/Node/LazyFolder.php","line":142,"function":"__call","class":"OC\\Files\\Node\\LazyFolder","type":"->"},{"file":"/var/www/html/nextcloud/lib/private/Files/AppData/AppData.php","line":141,"function":"get","class":"OC\\Files\\Node\\LazyFolder","type":"->"},{"file":"/var/www/html/nextcloud/lib/private/Template/JSCombiner.php","line":96,"function":"getFolder","class":"OC\\Files\\AppData\\AppData","type":"->"},{"file":"/var/www/html/nextcloud/lib/private/Template/JSResourceLocator.php","line":115,"function":"process","class":"OC\\Template\\JSCombiner","type":"->"},{"file":"/var/www/html/nextcloud/lib/private/Template/JSResourceLocator.php","line":71,"function":"cacheAndAppendCombineJsonIfExist","class":"OC\\Template\\JSResourceLocator","type":"->"},{"file":"/var/www/html/nextcloud/lib/private/Template/ResourceLocator.php","line":78,"function":"doFind","class":"OC\\Template\\JSResourceLocator","type":"->"},{"file":"/var/www/html/nextcloud/lib/private/TemplateLayout.php","line":388,"function":"find","class":"OC\\Template\\ResourceLocator","type":"->"},{"file":"/var/www/html/nextcloud/lib/private/TemplateLayout.php","line":216,"function":"findJavascriptFiles","class":"OC\\TemplateLayout","type":"::"},{"file":"/var/www/html/nextcloud/lib/private/legacy/OC_Template.php","line":182,"function":"__construct","class":"OC\\TemplateLayout","type":"->"},{"file":"/var/www/html/nextcloud/lib/private/Template/Base.php","line":132,"function":"fetchPage","class":"OC_Template","type":"->"},{"file":"/var/www/html/nextcloud/lib/private/legacy/OC_Template.php","line":331,"function":"printPage","class":"OC\\Template\\Base","type":"->"},{"file":"/var/www/html/nextcloud/index.php","line":74,"function":"printExceptionErrorPage","class":"OC_Template","type":"::"}],"File":"/var/www/html/nextcloud/lib/private/DB/Connection.php","Line":87,"CustomMessage":"--"}}

There is enough disk space. It looks like the MariaDB is overloaded.

MariaDB is logging this at the moment that Nextcloud crashed:

2022-02-19 10:43:08 0 [Note] InnoDB: File './ibtmp1' size is now 12 MB.
2022-02-19 10:43:08 0 [Note] InnoDB: 10.5.12 started; log sequence number 1306923128; transaction id 729513
2022-02-19 10:43:08 0 [Note] Plugin 'FEEDBACK' is disabled.
2022-02-19 10:43:08 0 [Note] InnoDB: Loading buffer pool(s) from /var/lib/mysql/ib_buffer_pool
2022-02-19 10:43:08 0 [Note] Server socket created on IP: '127.0.0.1'.
2022-02-19 10:43:08 0 [Note] Reading of all Master_info entries succeeded
2022-02-19 10:43:08 0 [Note] Added new Master_info '' to hash table
2022-02-19 10:43:08 0 [Note] /usr/sbin/mariadbd: ready for connections.
Version: '10.5.12-MariaDB-0+deb11u1'  socket: '/run/mysqld/mysqld.sock'  port: 3306  Debian 11
2022-02-19 10:43:09 0 [Note] InnoDB: Buffer pool(s) load completed at 220219 10:43:09
2022-02-19 10:44:54 196 [Warning] Aborted connection 196 to db: 'nextcloud' user: 'nextclouduser' host: 'localhost' (Got an error reading communication packets)
2022-02-19 10:44:54 203 [Warning] Aborted connection 203 to db: 'nextcloud' user: 'nextclouduser' host: 'localhost' (Got an error reading communication packets)
2022-02-19 10:44:54 198 [Warning] Aborted connection 198 to db: 'nextcloud' user: 'nextclouduser' host: 'localhost' (Got an error reading communication packets)
2022-02-19 10:44:54 200 [Warning] Aborted connection 200 to db: 'nextcloud' user: 'nextclouduser' host: 'localhost' (Got an error reading communication packets)
2022-02-19 10:44:54 154 [Warning] Aborted connection 154 to db: 'nextcloud' user: 'nextclouduser' host: 'localhost' (Got an error reading communication packets)
2022-02-19 10:44:54 194 [Warning] Aborted connection 194 to db: 'nextcloud' user: 'nextclouduser' host: 'localhost' (Got an error reading communication packets)
2022-02-19 10:44:54 193 [Warning] Aborted connection 193 to db: 'nextcloud' user: 'nextclouduser' host: 'localhost' (Got an error reading communication packets)
2022-02-19 10:44:54 195 [Warning] Aborted connection 195 to db: 'nextcloud' user: 'nextclouduser' host: 'localhost' (Got an error reading communication packets)
2022-02-19 10:44:54 192 [Warning] Aborted connection 192 to db: 'nextcloud' user: 'nextclouduser' host: 'localhost' (Got an error reading communication packets)

Nextcloud version (eg, 20.0.5): 23.0.0.10
Operating system and version (eg, Ubuntu 20.04): Debian GNU/Linux 11 (bullseye)
Apache or nginx version (eg, Apache 2.4.25): nginx/1.18.0
PHP version (eg, 7.4): PHP 7.4.25

The config is very standard and basic, local MariaDB database, only change is that the parameter “datadirectory” is pointed to a nfs mounting point.