SVGHMI: Fixed typo on session manager unregister, leading to wrong count of sessions and then exceptions when creating more session than allowed in protocol options. Also added more safety check in protocol in case session would be missing. svghmi
authorEdouard Tisserant
Tue, 13 Jul 2021 16:16:58 +0200
branchsvghmi
changeset 3278 2bcfbea6a2a8
parent 3277 8e81e4ce9bc6
child 3279 5615e062a77d
SVGHMI: Fixed typo on session manager unregister, leading to wrong count of sessions and then exceptions when creating more session than allowed in protocol options. Also added more safety check in protocol in case session would be missing.
svghmi/svghmi_server.py
--- a/svghmi/svghmi_server.py	Tue Jul 13 16:13:21 2021 +0200
+++ b/svghmi/svghmi_server.py	Tue Jul 13 16:16:58 2021 +0200
@@ -97,7 +97,7 @@
                 self.watchdog_session = None
             else:
                 try:
-                    self.multiclient_sessions.remove(self)
+                    self.multiclient_sessions.remove(session)
                 except KeyError:
                     return
             self.free_index(session.session_index)
@@ -214,19 +214,20 @@
     def onOpen(self):
         global svghmi_session_manager
         assert(self._hmi_session is None)
-        self._hmi_session = HMISession(self)
-        registered = svghmi_session_manager.register(self._hmi_session)
+        _hmi_session = HMISession(self)
+        registered = svghmi_session_manager.register(_hmi_session)
+        self._hmi_session = _hmi_session
 
     def onClose(self, wasClean, code, reason):
         global svghmi_session_manager
+        if self._hmi_session is None : return
         self._hmi_session.notify_closed()
         svghmi_session_manager.unregister(self._hmi_session)
         self._hmi_session = None
 
     def onMessage(self, msg, isBinary):
         global svghmi_watchdog
-        assert(self._hmi_session is not None)
-
+        if self._hmi_session is None : return
         result = self._hmi_session.onMessage(msg)
         if result == 1 and self.has_watchdog:  # was heartbeat
             if svghmi_watchdog is not None: