Ensure websocket termination handled correctly
Currently when a websocket is terminated on the client side, the logic
in EventNotifier continues to run. This is because the WebSocketError
exceptions are detected in the properties/interface handlers where
that exception is just ignored.
This exception can not be sent back up to the main loop because
it goes through the dbus libraries which will fail when it
sees it.
Use a class variable to indicate when a websocket error has
been hit and break out of the loop. Also, remove signal handlers.
Signed-off-by: Andrew Geissler <geissonator@yahoo.com>
Signed-off-by: Deepak Kodihalli <dkodihal@in.ibm.com>
Removed good path tracing.
Signed-off-by: Brad Bishop <bradleyb@fuzziesquirrel.com>
Change-Id: I068f19fd75aa03fb71d98e9ff75f596941c8622f
diff --git a/module/obmc/wsgi/apps/rest_dbus.py b/module/obmc/wsgi/apps/rest_dbus.py
index bf7db41..a0f6e4d 100644
--- a/module/obmc/wsgi/apps/rest_dbus.py
+++ b/module/obmc/wsgi/apps/rest_dbus.py
@@ -967,22 +967,26 @@
self.wsock = wsock
self.paths = filters.get("paths", [])
self.interfaces = filters.get("interfaces", [])
+ self.signals = []
+ self.socket_error = False
if not self.paths:
self.paths.append(None)
bus = dbus.SystemBus()
# Add a signal receiver for every path the client is interested in
for path in self.paths:
- bus.add_signal_receiver(
+ add_sig = bus.add_signal_receiver(
self.interfaces_added_handler,
dbus_interface=dbus.BUS_DAEMON_IFACE + '.ObjectManager',
signal_name='InterfacesAdded',
path=path)
- bus.add_signal_receiver(
+ chg_sig = bus.add_signal_receiver(
self.properties_changed_handler,
dbus_interface=dbus.PROPERTIES_IFACE,
signal_name='PropertiesChanged',
path=path,
path_keyword='path')
+ self.signals.append(add_sig)
+ self.signals.append(chg_sig)
loop = gobject.MainLoop()
# gobject's mainloop.run() will block the entire process, so the gevent
# scheduler and hence greenlets won't execute. The while-loop below
@@ -991,6 +995,11 @@
gcontext = loop.get_context()
while loop is not None:
try:
+ if self.socket_error:
+ for signal in self.signals:
+ signal.remove()
+ loop.quit()
+ break;
if gcontext.pending():
gcontext.iteration()
else:
@@ -1011,7 +1020,8 @@
response[self.keyNames['intfMap']] = iprops
try:
self.wsock.send(json.dumps(response))
- except WebSocketError:
+ except:
+ self.socket_error = True
return
def properties_changed_handler(self, interface, new, old, **kw):
@@ -1026,7 +1036,8 @@
response[self.keyNames['propMap']] = new
try:
self.wsock.send(json.dumps(response))
- except WebSocketError:
+ except:
+ self.socket_error = True
return