diff libervia/server/websockets.py @ 1206:d2e2bf14f2e2

server (websocket): don't crash if self.page doesn't exist while onClose is called
author Goffi <goffi@goffi.org>
date Sun, 14 Jul 2019 17:25:53 +0200
parents 251eba911d4d
children b2d067339de3
line wrap: on
line diff
--- a/libervia/server/websockets.py	Sun Jul 14 17:18:48 2019 +0200
+++ b/libervia/server/websockets.py	Sun Jul 14 17:25:53 2019 +0200
@@ -151,7 +151,14 @@
             cb(page, self.request, data_json)
 
     def onClose(self, wasClean, code, reason):
-        self.page.onSocketClose(self.request)
+        try:
+            page = self.page
+        except AttributeError:
+            log.debug(
+                u"page is not available, the socket was probably not opened cleanly.\n"
+                u"reason: {reason}".format(reason=reason))
+            return
+        page.onSocketClose(self.request)
 
         log.debug(
             _(