summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorIWAMOTO Toshihiro <iwamoto@valinux.co.jp>2016-06-30 10:27:22 +0900
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2016-07-01 11:30:01 +0900
commitb0ab4f16028c452374c5a0f22bd970038194f142 (patch)
treec9e4ad25d34ecbee6fde415b0fb9b2d119a3e748
parentd079bf38e784598f4208c06dd441f69bebec11f1 (diff)
Avoid parallel executions of AppManager.close()
If an AppManager.close call is started and all AppManager.services are stopped, AppManager.run_apps starts another close() call, resulting in a KeyError exception in close() (*1). Prevent that using a semaphore. (*1) https://launchpad.net/bugs/1589746 Signed-off-by: IWAMOTO Toshihiro <iwamoto@valinux.co.jp> Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
-rw-r--r--ryu/base/app_manager.py12
1 files changed, 8 insertions, 4 deletions
diff --git a/ryu/base/app_manager.py b/ryu/base/app_manager.py
index 13e41f42..f6842591 100644
--- a/ryu/base/app_manager.py
+++ b/ryu/base/app_manager.py
@@ -386,6 +386,7 @@ class AppManager(object):
self.applications = {}
self.contexts_cls = {}
self.contexts = {}
+ self.close_sem = hub.Semaphore()
def load_app(self, name):
mod = utils.import_module(name)
@@ -541,7 +542,10 @@ class AppManager(object):
self._close(app)
close_dict.clear()
- for app_name in list(self.applications.keys()):
- self.uninstantiate(app_name)
- assert not self.applications
- close_all(self.contexts)
+ # This semaphore prevents parallel execution of this function,
+ # as run_apps's finally clause starts another close() call.
+ with self.close_sem:
+ for app_name in list(self.applications.keys()):
+ self.uninstantiate(app_name)
+ assert not self.applications
+ close_all(self.contexts)