-
Notifications
You must be signed in to change notification settings - Fork 113
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
Concurrency? #10
Comments
Hi. I'm not sure what you mean, this part of the code checks that case: User existingUser = service.getUserbyUsername(user.getUsername());
if(existingUser == null) {
service.registerUser(user);
res.redirect("/login?r=1");
halt();
} else {
error = "The username is already taken";
} Are you saying this is not working? Well, It's possible due to concurrency, isolation level of the db, etc. |
Yeah. I mean, what if: Thread1: user1 -> getUserbyUsername('jimmy') -> none found -> registerUser('jimmy') Then two jimmy users are created. |
Right, it's not likely, but it can happen. Assuming the application is using a single database (or a cluster that can be seen as a single database), the easiest way to solve this could be at the database level, adding a unique constraint to the username column, so the second insertion fails. |
Hi, If multiple users register with same name at the same time, shouldn't this "select and insert" approach fail?
The text was updated successfully, but these errors were encountered: