Opened 7 years ago

Closed 7 years ago

Last modified 7 years ago

#29202 closed Bug (needsinfo)

KeyError in django-sites caching (race condition?)

Reported by: Dominik George Owned by: nobody
Component: contrib.sites Version: 1.10
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Django Version: 1.10.8
Python Version: 3.5.3

Relevant backtrace:

File
"/srv/www/teckids-website/venv/lib/python3.5/site-packages/django/contrib/sites/models.py"
in _get_site_by_id
  37.         return SITE_CACHE[site_id]

File "/srv/www/teckids-website/venv/lib/python3.5/site-packages/multisite/hacks.py" in
__getitem__
  124.             raise KeyError(key)

In theory, there cannot be a KeyError there, unless the cache is cleared while the method is running. The code does not seem to be thread-safe.

Change History (6)

comment:1 by Dominik George, 7 years ago

After a discussion at Chemnitzer Linux-Tage with some Django people, we agreed it is a bug, but maybe related to Apache mpm_prefork's multi-threading behaviour.

We reduced the threads in each process to 1 in the mod_wsgi config, but the error still occured after that.

comment:2 by Tim Graham, 7 years ago

I'm not sure. The fact that the traceback involves multisite/hacks.py (which is not part of Django) looks a bit suspicious.

comment:3 by Dominik George, 7 years ago

Yeah. I am not saying the CMS isn't part of the problem, but I don't need a backtrace to tell that the code in Django is neither thread-safe nor otherwise good practice ☺.

comment:4 by Tim Graham, 7 years ago

I'm skeptical because I'd think that if this were a common issue, we'd have seen it reported before now.

I don't know what can be done. Are you able to offer a patch?

comment:5 by Tim Graham, 7 years ago

Resolution: needsinfo
Status: newclosed
Version 0, edited 7 years ago by Tim Graham (next)

comment:6 by Dominik George, 7 years ago

Nope, it's not a duplicate.

Note: See TracTickets for help on using tickets.
Back to Top