changeset 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 92d0a2b785fd
children 67ec22356457
files libervia/server/websockets.py
diffstat 1 files changed, 8 insertions(+), 1 deletions(-) [+]
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(
             _(