diff options
author | Alexander Makarov <amakarov@mirantis.com> | 2015-08-27 17:25:52 +0300 |
---|---|---|
committer | Alexander Makarov <amakarov@mirantis.com> | 2015-08-28 15:04:44 +0300 |
commit | 6757913f0f7bf36c845a222cd8e5691a4d07c503 (patch) | |
tree | 60712e2f8aba62f7de35797fbd0594ac38df00d9 | |
parent | 1e05037c2ae02a4d52d0f50abf00d61021971508 (diff) | |
download | pbr-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
-rw-r--r-- | pbr/packaging.py | 9 | ||||
-rw-r--r-- | pbr/tests/test_wsgi.py | 2 |
2 files changed, 9 insertions, 2 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() """ diff --git a/pbr/tests/test_wsgi.py b/pbr/tests/test_wsgi.py index 9eded63..ea65fed 100644 --- a/pbr/tests/test_wsgi.py +++ b/pbr/tests/test_wsgi.py @@ -164,7 +164,7 @@ class TestWsgiScripts(base.BaseTestCase): "%s" % app_name) else_block = """else: - application = %s()""" % app_name + application = None""" self.assertIn(main_block, script_txt) self.assertIn(starting_block, script_txt) |