Dockerized NextCloud installation: Internal server error

I have migrated a dockerized NextCloud installation to a new server but I am receiving error messages “Internal server error”:

Nextcloud version: 25.0.3
Operating system and version: Ubuntu 22.04

I have checked the output of Nextcloud log in Admin > Logging:

There are many similar messages like

{"reqId":"ti9gnxkELGw1NBGbjOkZ","level":3,"time":"2023-02-12T19:30:38+00:00","remoteAddr":"145.40.196.129","user":"wlojak","app":"webdav","method":"PROPFIND","url":"/remote.php/dav/files/wlojak/SONAR-Shared","message":"OC\\DB\\Exceptions\\DbalException: An exception occurred while executing a query: SQLSTATE[40001]: Serialization failure: 1213 Deadlock found when trying to get lock; try restarting transaction","userAgent":"Mozilla/5.0 (Macintosh) mirall/2.6.5stable (build 20200710) (Nextcloud)","version":"25.0.2.3","exception":{"Exception":"Sabre\\DAV\\Exception\\ServiceUnavailable","Message":"OC\\DB\\Exceptions\\DbalException: An exception occurred while executing a query: SQLSTATE[40001]: Serialization failure: 1213 Deadlock found when trying to get lock; try restarting transaction","Code":0,"Trace":[{"file":"/var/www/html/3rdparty/sabre/dav/lib/DAV/Auth/Plugin.php","line":180,"function":"check","class":"OCA\\DAV\\Connector\\Sabre\\Auth","type":"->","args":[{"__class__":"Sabre\\HTTP\\Request"},{"__class__":"Sabre\\HTTP\\Response"}]},{"file":"/var/www/html/3rdparty/sabre/dav/lib/DAV/Auth/Plugin.php","line":135,"function":"check","class":"Sabre\\DAV\\Auth\\Plugin","type":"->","args":[{"__class__":"Sabre\\HTTP\\Request"},{"__class__":"Sabre\\HTTP\\Response"}]},{"file":"/var/www/html/3rdparty/sabre/event/lib/WildcardEmitterTrait.php","line":89,"function":"beforeMethod","class":"Sabre\\DAV\\Auth\\Plugin","type":"->","args":[{"__class__":"Sabre\\HTTP\\Request"},{"__class__":"Sabre\\HTTP\\Response"}]},{"file":"/var/www/html/3rdparty/sabre/dav/lib/DAV/Server.php","line":456,"function":"emit","class":"Sabre\\DAV\\Server","type":"->","args":["beforeMethod:PROPFIND",[{"__class__":"Sabre\\HTTP\\Request"},{"__class__":"Sabre\\HTTP\\Response"}]]},{"file":"/var/www/html/3rdparty/sabre/dav/lib/DAV/Server.php","line":253,"function":"invokeMethod","class":"Sabre\\DAV\\Server","type":"->","args":[{"__class__":"Sabre\\HTTP\\Request"},{"__class__":"Sabre\\HTTP\\Response"}]},{"file":"/var/www/html/3rdparty/sabre/dav/lib/DAV/Server.php","line":321,"function":"start","class":"Sabre\\DAV\\Server","type":"->","args":[]},{"file":"/var/www/html/apps/dav/lib/Server.php","line":360,"function":"exec","class":"Sabre\\DAV\\Server","type":"->","args":[]},{"file":"/var/www/html/apps/dav/appinfo/v2/remote.php","line":35,"function":"exec","class":"OCA\\DAV\\Server","type":"->","args":[]},{"file":"/var/www/html/remote.php","line":171,"args":["/var/www/html/apps/dav/appinfo/v2/remote.php"],"function":"require_once"}],"File":"/var/www/html/apps/dav/lib/Connector/Sabre/Auth.php","Line":143,"message":"OC\\DB\\Exceptions\\DbalException: An exception occurred while executing a query: SQLSTATE[40001]: Serialization failure: 1213 Deadlock found when trying to get lock; try restarting transaction","exception":[],"CustomMessage":"OC\\DB\\Exceptions\\DbalException: An exception occurred while executing a query: SQLSTATE[40001]: Serialization failure: 1213 Deadlock found when trying to get lock; try restarting transaction"},"id":"63f636400e18d"}

or

{"reqId":"6btMVJ6IdPDqzBhg6rFH","level":3,"time":"2023-02-12T20:19:34+00:00","remoteAddr":"78.43.252.143","user":"xian","app":"no app in context","method":"PUT","url":"/remote.php/dav/files/xian/Instructions/Isomorph/LDAP/Apache%20Directory%20Studio.md","message":"\"Instructions/Isomorph/LDAP/Apache Directory Studio.md\" is locked","userAgent":"Mozilla/5.0 (Macintosh) mirall/3.3.4git (build 7471) (Nextcloud, osx-20.6.0 ClientArchitecture: x86_64 OsArchitecture: x86_64)","version":"25.0.2.3","exception":{"Exception":"OCA\\DAV\\Connector\\Sabre\\Exception\\FileLocked","Message":"\"Instructions/Isomorph/LDAP/Apache Directory Studio.md\" is locked","Code":0,"Trace":[{"file":"/var/www/html/3rdparty/sabre/dav/lib/DAV/Server.php","line":1137,"function":"put","class":"OCA\\DAV\\Connector\\Sabre\\File","type":"->","args":["*** sensitive parameters replaced ***"]},{"file":"/var/www/html/3rdparty/sabre/dav/lib/DAV/CorePlugin.php","line":492,"function":"updateFile","class":"Sabre\\DAV\\Server","type":"->","args":["*** sensitive parameters replaced ***"]},{"file":"/var/www/html/3rdparty/sabre/event/lib/WildcardEmitterTrait.php","line":89,"function":"httpPut","class":"Sabre\\DAV\\CorePlugin","type":"->","args":[{"__class__":"Sabre\\HTTP\\Request"},{"__class__":"Sabre\\HTTP\\Response"}]},{"file":"/var/www/html/3rdparty/sabre/dav/lib/DAV/Server.php","line":472,"function":"emit","class":"Sabre\\DAV\\Server","type":"->","args":["method:PUT",[{"__class__":"Sabre\\HTTP\\Request"},{"__class__":"Sabre\\HTTP\\Response"}]]},{"file":"/var/www/html/3rdparty/sabre/dav/lib/DAV/Server.php","line":253,"function":"invokeMethod","class":"Sabre\\DAV\\Server","type":"->","args":[{"__class__":"Sabre\\HTTP\\Request"},{"__class__":"Sabre\\HTTP\\Response"}]},{"file":"/var/www/html/3rdparty/sabre/dav/lib/DAV/Server.php","line":321,"function":"start","class":"Sabre\\DAV\\Server","type":"->","args":[]},{"file":"/var/www/html/apps/dav/lib/Server.php","line":360,"function":"exec","class":"Sabre\\DAV\\Server","type":"->","args":[]},{"file":"/var/www/html/apps/dav/appinfo/v2/remote.php","line":35,"function":"exec","class":"OCA\\DAV\\Server","type":"->","args":[]},{"file":"/var/www/html/remote.php","line":171,"args":["/var/www/html/apps/dav/appinfo/v2/remote.php"],"function":"require_once"}],"File":"/var/www/html/apps/dav/lib/Connector/Sabre/File.php","Line":204,"Previous":{"Exception":"OCP\\Lock\\LockedException","Message":"\"Instructions/Isomorph/LDAP/Apache Directory Studio.md\" is locked","Code":0,"Trace":[{"file":"/var/www/html/apps/dav/lib/Connector/Sabre/Node.php","line":412,"function":"changeLock","class":"OC\\Files\\View","type":"->","args":["/Instructions/Isomorph/LDAP/Apache Directory Studio.md",2]},{"file":"/var/www/html/apps/dav/lib/Connector/Sabre/File.php","line":191,"function":"changeLock","class":"OCA\\DAV\\Connector\\Sabre\\Node","type":"->","args":[2]},{"file":"/var/www/html/3rdparty/sabre/dav/lib/DAV/Server.php","line":1137,"function":"put","class":"OCA\\DAV\\Connector\\Sabre\\File","type":"->","args":["*** sensitive parameters replaced ***"]},{"file":"/var/www/html/3rdparty/sabre/dav/lib/DAV/CorePlugin.php","line":492,"function":"updateFile","class":"Sabre\\DAV\\Server","type":"->","args":["*** sensitive parameters replaced ***"]},{"file":"/var/www/html/3rdparty/sabre/event/lib/WildcardEmitterTrait.php","line":89,"function":"httpPut","class":"Sabre\\DAV\\CorePlugin","type":"->","args":[{"__class__":"Sabre\\HTTP\\Request"},{"__class__":"Sabre\\HTTP\\Response"}]},{"file":"/var/www/html/3rdparty/sabre/dav/lib/DAV/Server.php","line":472,"function":"emit","class":"Sabre\\DAV\\Server","type":"->","args":["method:PUT",[{"__class__":"Sabre\\HTTP\\Request"},{"__class__":"Sabre\\HTTP\\Response"}]]},{"file":"/var/www/html/3rdparty/sabre/dav/lib/DAV/Server.php","line":253,"function":"invokeMethod","class":"Sabre\\DAV\\Server","type":"->","args":[{"__class__":"Sabre\\HTTP\\Request"},{"__class__":"Sabre\\HTTP\\Response"}]},{"file":"/var/www/html/3rdparty/sabre/dav/lib/DAV/Server.php","line":321,"function":"start","class":"Sabre\\DAV\\Server","type":"->","args":[]},{"file":"/var/www/html/apps/dav/lib/Server.php","line":360,"function":"exec","class":"Sabre\\DAV\\Server","type":"->","args":[]},{"file":"/var/www/html/apps/dav/appinfo/v2/remote.php","line":35,"function":"exec","class":"OCA\\DAV\\Server","type":"->","args":[]},{"file":"/var/www/html/remote.php","line":171,"args":["/var/www/html/apps/dav/appinfo/v2/remote.php"],"function":"require_once"}],"File":"/var/www/html/lib/private/Files/View.php","Line":2012,"Previous":{"Exception":"OCP\\Lock\\LockedException","Message":"\"files/3f54e165faeca547fc51b158e3f875a7\" is locked","Code":0,"Trace":[{"file":"/var/www/html/lib/private/Files/Storage/Common.php","line":827,"function":"changeLock","class":"OC\\Lock\\DBLockingProvider","type":"->","args":["files/3f54e165faeca547fc51b158e3f875a7",2]},{"file":"/var/www/html/lib/private/Files/Storage/Wrapper/Wrapper.php","line":632,"function":"changeLock","class":"OC\\Files\\Storage\\Common","type":"->","args":["files/Notebooks/Instructions/Isomorph/LDAP/Apache Directory Studio.md",2,{"__class__":"OC\\Lock\\DBLockingProvider"}]},{"file":"/var/www/html/lib/private/Files/Storage/Wrapper/Wrapper.php","line":632,"function":"changeLock","class":"OC\\Files\\Storage\\Wrapper\\Wrapper","type":"->","args":["files/Notebooks/Instructions/Isomorph/LDAP/Apache Directory Studio.md",2,{"__class__":"OC\\Lock\\DBLockingProvider"}]},{"file":"/var/www/html/lib/private/Files/Storage/Wrapper/Wrapper.php","line":632,"function":"changeLock","class":"OC\\Files\\Storage\\Wrapper\\Wrapper","type":"->","args":["files/Notebooks/Instructions/Isomorph/LDAP/Apache Directory Studio.md",2,{"__class__":"OC\\Lock\\DBLockingProvider"}]},{"file":"/var/www/html/apps/files_sharing/lib/SharedStorage.php","line":507,"function":"changeLock","class":"OC\\Files\\Storage\\Wrapper\\Wrapper","type":"->","args":["files/Notebooks/Instructions/Isomorph/LDAP/Apache Directory Studio.md",2,{"__class__":"OC\\Lock\\DBLockingProvider"}]},{"file":"/var/www/html/lib/private/Files/Storage/Wrapper/Wrapper.php","line":632,"function":"changeLock","class":"OCA\\Files_Sharing\\SharedStorage","type":"->","args":["Isomorph/LDAP/Apache Directory Studio.md",2,{"__class__":"OC\\Lock\\DBLockingProvider"}]},{"file":"/var/www/html/lib/private/Files/View.php","line":2006,"function":"changeLock","class":"OC\\Files\\Storage\\Wrapper\\Wrapper","type":"->","args":["Isomorph/LDAP/Apache Directory Studio.md",2,{"__class__":"OC\\Lock\\DBLockingProvider"}]},{"file":"/var/www/html/apps/dav/lib/Connector/Sabre/Node.php","line":412,"function":"changeLock","class":"OC\\Files\\View","type":"->","args":["/Instructions/Isomorph/LDAP/Apache Directory Studio.md",2]},{"file":"/var/www/html/apps/dav/lib/Connector/Sabre/File.php","line":191,"function":"changeLock","class":"OCA\\DAV\\Connector\\Sabre\\Node","type":"->","args":[2]},{"file":"/var/www/html/3rdparty/sabre/dav/lib/DAV/Server.php","line":1137,"function":"put","class":"OCA\\DAV\\Connector\\Sabre\\File","type":"->","args":["*** sensitive parameters replaced ***"]},{"file":"/var/www/html/3rdparty/sabre/dav/lib/DAV/CorePlugin.php","line":492,"function":"updateFile","class":"Sabre\\DAV\\Server","type":"->","args":["*** sensitive parameters replaced ***"]},{"file":"/var/www/html/3rdparty/sabre/event/lib/WildcardEmitterTrait.php","line":89,"function":"httpPut","class":"Sabre\\DAV\\CorePlugin","type":"->","args":[{"__class__":"Sabre\\HTTP\\Request"},{"__class__":"Sabre\\HTTP\\Response"}]},{"file":"/var/www/html/3rdparty/sabre/dav/lib/DAV/Server.php","line":472,"function":"emit","class":"Sabre\\DAV\\Server","type":"->","args":["method:PUT",[{"__class__":"Sabre\\HTTP\\Request"},{"__class__":"Sabre\\HTTP\\Response"}]]},{"file":"/var/www/html/3rdparty/sabre/dav/lib/DAV/Server.php","line":253,"function":"invokeMethod","class":"Sabre\\DAV\\Server","type":"->","args":[{"__class__":"Sabre\\HTTP\\Request"},{"__class__":"Sabre\\HTTP\\Response"}]},{"file":"/var/www/html/3rdparty/sabre/dav/lib/DAV/Server.php","line":321,"function":"start","class":"Sabre\\DAV\\Server","type":"->","args":[]},{"file":"/var/www/html/apps/dav/lib/Server.php","line":360,"function":"exec","class":"Sabre\\DAV\\Server","type":"->","args":[]},{"file":"/var/www/html/apps/dav/appinfo/v2/remote.php","line":35,"function":"exec","class":"OCA\\DAV\\Server","type":"->","args":[]},{"file":"/var/www/html/remote.php","line":171,"args":["/var/www/html/apps/dav/appinfo/v2/remote.php"],"function":"require_once"}],"File":"/var/www/html/lib/private/Lock/DBLockingProvider.php","Line":220}},"message":"\"Instructions/Isomorph/LDAP/Apache Directory Studio.md\" is locked","exception":[],"CustomMessage":"\"Instructions/Isomorph/LDAP/Apache Directory Studio.md\" is locked"},"id":"63f636400e13e"}

I am able to login to NextCloud but I cannot synchronize by using the NextCloud sync client: when authenticating I receive the following message:

Internal Server Error

The server was unable to complete your request.

If this happens again, please send the technical details below to the server administrator.

More details can be found in the server log.

### Technical details

* Remote Address: 172.20.0.3
* Request ID: WgTzMmMdXhwJ7TQCT24y

How can I resolve the problem?

I have further investigated the Admin>Logging output and found a more detailed error message when trying to login to the NextCloud sync client:

	Exception: OC\Core\Controller\ClientFlowLoginV2Controller::grantPage(): Argument #1 ($stateToken) must be of type string, null given, called in /var/www/html/lib/private/AppFramework/Http/Dispatcher.php on line 225 in file '/var/www/html/core/Controller/ClientFlowLoginV2Controller.php' line 152

    /var/www/html/lib/private/AppFramework/App.php - line 172:

    OC\AppFramework\Http\Dispatcher->dispatch(OC\Core\Cont ... {}, "grantPage")

    /var/www/html/lib/private/Route/Router.php - line 298:

    OC\AppFramework\App::main("OC\\Core\\C ... r", "grantPage", OC\AppFramew ... {}, [ "core.Clie ... "])

    /var/www/html/lib/base.php - line 1047:

    OC\Route\Router->match("/login/v2/grant")

    /var/www/html/index.php - line 36:

    OC::handleRequest()

Caused by TypeError: OC\Core\Controller\ClientFlowLoginV2Controller::grantPage(): Argument #1 ($stateToken) must be of type string, null given, called in /var/www/html/lib/private/AppFramework/Http/Dispatcher.php on line 225

    /var/www/html/lib/private/AppFramework/Http/Dispatcher.php - line 225:

    OC\Core\Controller\ClientFlowLoginV2Controller->grantPage(null)

    /var/www/html/lib/private/AppFramework/Http/Dispatcher.php - line 133:

    OC\AppFramework\Http\Dispatcher->executeController(OC\Core\Cont ... {}, "grantPage")

    /var/www/html/lib/private/AppFramework/App.php - line 172:

    OC\AppFramework\Http\Dispatcher->dispatch(OC\Core\Cont ... {}, "grantPage")

    /var/www/html/lib/private/Route/Router.php - line 298:

    OC\AppFramework\App::main("OC\\Core\\C ... r", "grantPage", OC\AppFramew ... {}, [ "core.Clie ... "])

    /var/www/html/lib/base.php - line 1047:

    OC\Route\Router->match("/login/v2/grant")

    /var/www/html/index.php - line 36:

    OC::handleRequest()

However, I don’t have any idea what to do with this error message?

This issue seems to be a bug which is already described on
github: I copied and opened the authorization link provided by the customer in the browser. After the first page it redirects to another page and I noticed that the URL had a GET “User=” argument (or similar, without the value). I put my user in front of it “User=myuser” and pressed the enter key. So I gave the permissions. After that, I opened the authorization link provided by the client again, followed the normal procedure and the client was authenticated.