-
Notifications
You must be signed in to change notification settings - Fork 43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix project creation conflict during user creation #3815
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this is a hack to get around an immediate bug, feel free to merge, but please also open an issue for the proper fix
@@ -78,7 +80,13 @@ func (s *Server) CreateUser(ctx context.Context, | |||
// Set up the default project for the user | |||
baseName := subject | |||
if token.PreferredUsername() != "" { | |||
baseName = token.PreferredUsername() | |||
// Check if `project_name_lower_idx` unique constraint was violated. This happens when |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this an outdated comment? We check the other way around, to see if there's sql.ErrNoRows
returned right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right, this was a leftover copy-pasta from the other place where we had this check 👍
// getUniqueProjectBaseName is used to generate a unique project name | ||
func getUniqueProjectBaseName(ctx context.Context, store db.Store, baseName string) (string, error) { | ||
uniqueBaseName := baseName | ||
for { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know it's unlikely we hit a really infinite loop here, but for {}
always makes me nervous. Do you think we could add some upper limit?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll add a 10 times retry mechanism. It should be more than enough 👍
e3d20c0
to
0caa6ba
Compare
Signed-off-by: Radoslav Dimitrov <radoslav@stacklok.com>
Signed-off-by: Radoslav Dimitrov <radoslav@stacklok.com>
0caa6ba
to
404d81a
Compare
* Fix project creation conflict during user creation Signed-off-by: Radoslav Dimitrov <radoslav@stacklok.com> * Add for loop retry counter and update comment Signed-off-by: Radoslav Dimitrov <radoslav@stacklok.com> --------- Signed-off-by: Radoslav Dimitrov <radoslav@stacklok.com>
Summary
The following PR fixes the conflict that may happen if the project we try to create during
CreateUser
already exists.The proposed solution checks if there's such project with that name, if there's appends a random 4 char string and tries again until it finds a unique combination.
Change Type
Mark the type of change your PR introduces:
Testing
Outline how the changes were tested, including steps to reproduce and any relevant configurations.
Attach screenshots if helpful.
Review Checklist: