summaryrefslogtreecommitdiff
path: root/pbr/packaging.py
diff options
context:
space:
mode:
authorAlexander Makarov <amakarov@mirantis.com>2015-08-27 17:25:52 +0300
committerAlexander Makarov <amakarov@mirantis.com>2015-08-28 15:04:44 +0300
commit6757913f0f7bf36c845a222cd8e5691a4d07c503 (patch)
tree60712e2f8aba62f7de35797fbd0594ac38df00d9 /pbr/packaging.py
parent1e05037c2ae02a4d52d0f50abf00d61021971508 (diff)
downloadpbr-6757913f0f7bf36c845a222cd8e5691a4d07c503.tar.gz
Protect WSGI application with a critical section
When configured as an Apache WSGI module a race condition is possible during keystone cache initialization. The operation raises exception region.RegionAlreadyConfigured. This is a result of the race condition involving global 'application' variable being initialized several times (1 per thread). Apache modwsgi documentation suggests protecting global objects with thread locks. Change-Id: Ib9e2207b0d1d9cee656736e94865fb404b6a868d Related-Bug: 1482271
Diffstat (limited to 'pbr/packaging.py')
-rw-r--r--pbr/packaging.py9
1 files changed, 8 insertions, 1 deletions
diff --git a/pbr/packaging.py b/pbr/packaging.py
index 672b8a7..f920374 100644
--- a/pbr/packaging.py
+++ b/pbr/packaging.py
@@ -250,6 +250,8 @@ def have_nose():
_wsgi_text = """#PBR Generated from %(group)r
+import threading
+
from %(module_name)s import %(import_target)s
if __name__ == "__main__":
@@ -275,7 +277,12 @@ if __name__ == "__main__":
server.serve_forever()
else:
- application = %(invoke_target)s()
+ application = None
+ app_lock = threading.Lock()
+
+ with app_lock:
+ if application is None:
+ application = %(invoke_target)s()
"""