summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJason Kölker <jason@koelker.net>2016-01-27 04:20:56 +0000
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2016-01-30 22:18:51 +0900
commita71c2a9e1b736a35a4a29d9e1d596c29ac022483 (patch)
treeb425bb66068ceb536270caf7f1467d04e038f1a8
parent636de20197aa2bd2d1ee8e9f6c6cd84d42b11270 (diff)
protocols/ovsdb: Forcably kill the main_thread
Should allow AppManager.run_apps to terminate. Signed-off-by: Jason Kölker <jason@koelker.net> Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
-rw-r--r--ryu/services/protocols/ovsdb/client.py11
-rw-r--r--ryu/services/protocols/ovsdb/manager.py18
2 files changed, 22 insertions, 7 deletions
diff --git a/ryu/services/protocols/ovsdb/client.py b/ryu/services/protocols/ovsdb/client.py
index 69d334fe..387d91b6 100644
--- a/ryu/services/protocols/ovsdb/client.py
+++ b/ryu/services/protocols/ovsdb/client.py
@@ -287,7 +287,7 @@ class RemoteOvsdb(app_manager.RyuApp):
except Exception:
self.logger.exception('Error running IDL for system_id %s' %
self.system_id)
- break
+ raise
hub.sleep(0)
@@ -295,7 +295,7 @@ class RemoteOvsdb(app_manager.RyuApp):
try:
func(*args, **kwargs)
- finally:
+ except:
self.stop()
def _transactions(self):
@@ -348,5 +348,10 @@ class RemoteOvsdb(app_manager.RyuApp):
self.threads.append(t)
def stop(self):
- super(RemoteOvsdb, self).stop()
+ # NOTE(jkoelker) Stop the idl and event_proxy threads first
+ # letting them finish their current loop.
+ self.is_active = False
+ hub.joinall(self.threads)
+
self._idl.close()
+ super(RemoteOvsdb, self).stop()
diff --git a/ryu/services/protocols/ovsdb/manager.py b/ryu/services/protocols/ovsdb/manager.py
index 16ea08af..327f2167 100644
--- a/ryu/services/protocols/ovsdb/manager.py
+++ b/ryu/services/protocols/ovsdb/manager.py
@@ -59,14 +59,15 @@ class OVSDB(app_manager.RyuApp):
def check(address):
return True
- while True:
+ while self.is_active:
try:
# TODO(jkoelker) SSL Certificate Fingerprint check
sock, client_address = server.accept()
except:
- self.logger.exception('Error accepting connection')
- continue
+ if self.is_active:
+ self.logger.exception('Error accepting connection')
+ continue
if not check(client_address[0]):
sock.shutdown(socket.SHUT_RDWR)
@@ -127,10 +128,19 @@ class OVSDB(app_manager.RyuApp):
return t
def stop(self):
- # TODO main_thread should be stopped first, not from super().stop
+ # NOTE(jkoelker) Attempt to gracefully stop the accept loop
+ self.is_active = False
+
+ # NOTE(jkoelker) Forceably kill the loop and clear the main_thread
+ if self.main_thread:
+ hub.kill(self.main_thread)
+ self.main_thread = None
+
+ # NOTE(jkoelker) Stop all the clients
for client in self._clients.values():
client.stop()
+ # NOTE(jkoelker) super will only take care of the event and joining now
super(OVSDB, self).stop()
@handler.set_ev_cls(event.EventModifyRequest)