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

possible race condition while generating username #41

Closed
marcinn opened this issue Mar 26, 2011 · 1 comment
Closed

possible race condition while generating username #41

marcinn opened this issue Mar 26, 2011 · 1 comment

Comments

@marcinn
Copy link

marcinn commented Mar 26, 2011

this code fragment is not thread safe (backends/init.py):

    name, idx = username, 2
    while True:
        try:
            name = fixer(name)
            User.objects.get(username=name)
            name = username + str(idx)
            idx += 1
        except User.DoesNotExist:
            username = name
            break

parallel processes or threads can generate same username and try to store same usernames. but the only one thread will write data, and others will raise IntegrityError.

using uuid instead of incrementing index is more safe. you can generate uuid and store it in base36.

greetz.

@omab
Copy link
Owner

omab commented Mar 29, 2011

User uuid4 to generate unique usernames. Closed by 05adbad

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

2 participants