18076: Fixes the bug by assigning a different (and random) username.
authorLucas Di Pentima <lucas.dipentima@curii.com>
Mon, 6 Sep 2021 19:41:40 +0000 (16:41 -0300)
committerLucas Di Pentima <lucas.dipentima@curii.com>
Mon, 6 Sep 2021 19:41:40 +0000 (16:41 -0300)
If the renamed user does exist on the LoginCluster, it'll eventually be named
correctly, and it is a stale record, it'll get a username that gives the admin
a clue about what happened to it.

Arvados-DCO-1.1-Signed-off-by: Lucas Di Pentima <lucas.dipentima@curii.com>

services/api/app/controllers/arvados/v1/users_controller.rb

index 82594c1eb3fb0996c4055b1f7a65120dc42b2524..ff4aecac478de8698aa191450bef7773859f7de6 100644 (file)
@@ -38,8 +38,9 @@ class Arvados::V1::UsersController < ApplicationController
             # A cached user record from the LoginCluster is stale, reset its username
             # and retry the update operation.
             if local_user.andand.uuid[0..4] == loginCluster && local_user.uuid != u.uuid
-              Rails.logger.warn("cached username '#{needupdate[:username]}' collision with user '#{local_user.uuid}' - resetting")
-              local_user.update_attributes!({username: nil})
+              new_username = "#{needupdate[:username]}conflict#{rand(99999999)}"
+              Rails.logger.warn("cached username '#{needupdate[:username]}' collision with user '#{local_user.uuid}' - renaming to '#{new_username}' before retrying")
+              local_user.update_attributes!({username: new_username})
               retry
             end
           end