Skip to content
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

refactor(app): Potential race conditions #424

Open
MR2011 opened this issue Dec 13, 2024 · 0 comments
Open

refactor(app): Potential race conditions #424

MR2011 opened this issue Dec 13, 2024 · 0 comments

Comments

@MR2011
Copy link
Collaborator

MR2011 commented Dec 13, 2024

Task Description

We use the following pattern across the CRUD operations in the app layer:

...
       users, err := u.ListUsers(f, &entity.ListOptions{})

	if err != nil {
		l.Error(err)
		return nil, NewUserHandlerError("Internal error while creating user.")
	}

	if len(users.Elements) > 0 {
		return nil, NewUserHandlerError(fmt.Sprintf("Duplicated entry %s for UniqueUserID.", user.UniqueUserID))
	}

	newUser, err := u.database.CreateUser(user)
...

Between the check if the user exists and the creation might occur a race condition. However, since we have a unique constraint on the database level, this will be prevented. In the future, we should avoid patterns these patterns by using transactions on the database layer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant