Do not unauthenticate if autocreation fails due to a race
authorGergő Tisza <gtisza@wikimedia.org>
Thu, 18 Feb 2016 02:10:31 +0000 (02:10 +0000)
committerGergő Tisza <gtisza@wikimedia.org>
Thu, 18 Feb 2016 03:13:36 +0000 (03:13 +0000)
Bug: T70012
Change-Id: I523ee94744ac943ede78af59ab381b65ae26e672

includes/session/SessionManager.php

index 5573ec7..e7a5e2e 100644 (file)
@@ -475,12 +475,21 @@ final class SessionManager implements SessionManagerInterface {
                        $status = $user->addToDatabase();
                        if ( !$status->isOK() ) {
                                // @codeCoverageIgnoreStart
-                               $logger->error( __METHOD__ . ': failed with message ' . $status->getWikiText(),
-                                       [
-                                               'username' => $userName,
-                               ] );
-                               $user->setId( 0 );
-                               $user->loadFromId();
+                               // double-check for a race condition (T70012)
+                               $id = User::idFromName( $user->getName(), User::READ_LATEST );
+                               if ( $id ) {
+                                       $logger->info( __METHOD__ . ': tried to autocreate existing user',
+                                               [
+                                                       'username' => $userName,
+                                               ] );
+                               } else {
+                                       $logger->error( __METHOD__ . ': failed with message ' . $status->getWikiText(),
+                                               [
+                                                       'username' => $userName,
+                                               ] );
+                               }
+                               $user->setId( $id );
+                               $user->loadFromId( User::READ_LATEST );
                                return false;
                                // @codeCoverageIgnoreEnd
                        }