FAQ | This is a LIVE service | Changelog

Skip to content

authentication: remove race condition in creating users

Dr Rich Wareham requested to merge github/fork/rjw57/user-creation-race into master

Previously we emulated a get_or_create behaviour for Users by attempting to get the user and, if that failed, create it.

This introduced a race where another worker could create a user between these checks. (We observed this in production when an initial log in causes a flurry of requests to lookupproxy.) This was a result of Django's autocommit mode since the user fetch and subsequent user creation were separate transactions allowing for database change between them.

The race-free approach is to always attempt to create the user and only if that fails do we fetch the user. These are still run as separate transactions but the user object will always be created by the first worker to talk to the DB and the rest will see an integrity error causing them to fetch the new user object.

Closes #21 (closed)

Merge request reports