#23642: LocMemCache.incr is not thread safe
-------------------------------------+--------------------
Reporter: tchaumeny | Owner: nobody
Type: Bug | Status: new
Component: Core (Cache system) | Version: master
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+--------------------
`LocMemCache` is documented as being thread-safe, but its `incr` operation
isn't: there is not lock wrapping the whole get+set operation.
The code below demonstrates the issue:
{{{
import threading
from django.core.cache.backends.locmem import LocMemCache
cache = LocMemCache('test', {})
cache.set('foo', 0)
def increment(key):
cache.incr(key)
threads = []
for i in range(20):
t = threading.Thread(target=increment, args=('foo',))
t.start()
threads.append(t)
for t in threads:
t.join()
print cache.get('foo') # Random results — 20 is expected
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/23642>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/052.d120a07c0c3be8ccef5206f5b1569406%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.