Opened 11 years ago
Closed 11 years ago
#23642 closed Bug (fixed)
LocMemCache.incr is not thread safe
| Reported by: | Thomas C | Owned by: | nobody |
|---|---|---|---|
| Component: | Core (Cache system) | Version: | dev |
| Severity: | Normal | Keywords: | |
| Cc: | Triage Stage: | Accepted | |
| Has patch: | yes | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description (last modified by )
LocMemCache is documented as being thread-safe, but its incr operation isn't: there is no 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
Change History (4)
comment:1 by , 11 years ago
| Description: | modified (diff) |
|---|
comment:2 by , 11 years ago
| Triage Stage: | Unreviewed → Accepted |
|---|
comment:3 by , 11 years ago
| Has patch: | set |
|---|
comment:4 by , 11 years ago
| Resolution: | → fixed |
|---|---|
| Status: | new → closed |
Note:
See TracTickets
for help on using tickets.
In 6448dd833524ac3fc503506b624841c9d642de8a: