OCP\Lock\LockedException: "/user.name" is locked

One user reported that it can’t login on Nextcloud and I found this error in the logs:

Error index OCP\Lock\LockedException: “/user.name” is locked
/var/www/nextcloud/lib/private/Files/View.php - line 1130: OC\Files\View->changeLock(‘/user.name’, 2)
/var/www/nextcloud/lib/private/Files/View.php - line 269: OC\Files\View->basicOperation(‘mkdir’, ‘/user.name’, Array)
/var/www/nextcloud/lib/private/Files/Node/Folder.php - line 160: OC\Files\View->mkdir(‘/user.name’)
/var/www/nextcloud/lib/private/Files/Node/Root.php - line 378: OC\Files\Node\Folder->newFolder(‘/user.name’)
[internal function] OC\Files\Node\Root->getUserFolder(‘user.name’)
/var/www/nextcloud/lib/private/Files/Node/LazyRoot.php - line 63: call_user_func_array(Array, Array)
/var/www/nextcloud/lib/private/Files/Node/LazyRoot.php - line 280: OC\Files\Node\LazyRoot->__call(‘getUserFolder’, Array)
/var/www/nextcloud/lib/private/Server.php - line 1175: OC\Files\Node\LazyRoot->getUserFolder(‘user.name’)
/var/www/nextcloud/lib/private/legacy/user.php - line 214: OC\Server->getUserFolder(‘user.name’)
/var/www/nextcloud/lib/private/legacy/user.php - line 238: OC_User loginWithApache(Object(OCA\User_SAML\UserBackend))
/var/www/nextcloud/apps/user_saml/appinfo/app.php - line 50: OC_User handleApacheAuth()
/var/www/nextcloud/lib/private/legacy/app.php - line 209: require_once(‘/var/www/nextcl…’)
/var/www/nextcloud/lib/private/legacy/app.php - line 149: OC_App requireAppFile(‘user_saml’)
/var/www/nextcloud/lib/private/legacy/app.php - line 124: OC_App loadApp(‘user_saml’)
/var/www/nextcloud/lib/base.php - line 982: OC_App loadApps(Array)
/var/www/nextcloud/index.php - line 48: OC handleRequest()
{main}

Does anyone know what could cause this and how can I fix it?

I found this fixed it for me:

MariaDB [nextcloud]> delete from oc_authtoken where uid = ‘<user’s uid here>’;

Just dumb luck that I noticed the oc_authtoken table referenced in a table when I tried to use the impersonate app to impersonate the user.

Looking at the whole error I saw that it failed to create the user data folder. At first look it did create the folder but later when I looked inside it the folder files was missing, so I created it and scanned that users files with “occ files:scan username”. This fixed the problem for me.