Fix race condition in available-prefix/ip APIs

Implement advisory lock to prevent duplicate records being inserted
when making simultaneous calls. Fixes #2519
This commit is contained in:
Matt Olenik
2019-12-13 11:52:59 -08:00
parent 2ab382eec5
commit 2e83ce76ed
4 changed files with 26 additions and 0 deletions

View File

@@ -27,3 +27,14 @@ COLOR_CHOICES = (
('111111', 'Black'),
('ffffff', 'White'),
)
# Keys for PostgreSQL advisory locks. These are arbitrary bigints used by
# the advisory_lock contextmanager. When a lock is acquired,
# one of these keys will be used to identify said lock.
#
# When adding a new key, pick something arbitrary and unique so
# that it is easily searchable in query logs.
ADVISORY_LOCK_KEYS = {
'available-prefixes': 100100,
'available-ips': 100200,
}