Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed #4909 -- Fixed a race condition with middleware initialisation …

…in multi-threaded setups. Thanks, colin@owlfish.com.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@5868 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 6d31e431c3bb09cf386c0fbef169a5307e689775 1 parent 3d012a1
@malcolmt malcolmt authored
Showing with 9 additions and 1 deletion.
  1. +1 −0  AUTHORS
  2. +8 −1 django/core/handlers/wsgi.py
View
1  AUTHORS
@@ -78,6 +78,7 @@ answer newbie questions, and generally made Django that much better:
Bryan Chow <bryan at verdjn dot com>
Michal Chruszcz <troll@pld-linux.org>
Ian Clelland <clelland@gmail.com>
+ colin@owlfish.com
crankycoder@gmail.com
Pete Crosier <pete.crosier@gmail.com>
Matt Croydon <http://www.postneo.com/>
View
9 django/core/handlers/wsgi.py
@@ -6,6 +6,7 @@
from django import http
from pprint import pformat
from shutil import copyfileobj
+from threading import Lock
try:
from cStringIO import StringIO
except ImportError:
@@ -176,13 +177,19 @@ def _get_raw_post_data(self):
raw_post_data = property(_get_raw_post_data)
class WSGIHandler(BaseHandler):
+ initLock = Lock()
+
def __call__(self, environ, start_response):
from django.conf import settings
# Set up middleware if needed. We couldn't do this earlier, because
# settings weren't available.
if self._request_middleware is None:
- self.load_middleware()
+ self.initLock.acquire()
+ # Check that middleware is still uninitialised.
+ if self._request_middleware is None:
+ self.load_middleware()
+ self.initLock.release()
dispatcher.send(signal=signals.request_started)
try:
Please sign in to comment.
Something went wrong with that request. Please try again.