frappy_psi.sea: avoid multiple connections

the _connect method was sometimes started in parallel
from startModules and the first call to doPoll.
remove the first one, and protect the second one
with a lock

Change-Id: I079439e150efd5d005130cef475f6326f933ecbd
Reviewed-on: https://forge.frm2.tum.de/review/c/secop/frappy/+/31611
Tested-by: Jenkins Automated Tests <pedersen+jenkins@frm2.tum.de>
Reviewed-by: Markus Zolliker <markus.zolliker@psi.ch>
This commit is contained in:
2023-07-07 15:37:38 +02:00
parent 8647814220
commit 78e8b9127f

View File

@ -138,7 +138,11 @@ class SeaClient(ProxyClient, Module):
def doPoll(self):
if not self.asynio and time.time() > self._last_connect + 10:
self._connect_thread = mkthread(self._connect, None)
with self._write_lock:
# make sure no more connect thread is running
if self._connect_thread and self._connect_thread.isAlive():
return
self._connect_thread = mkthread(self._connect, None)
def register_obj(self, module, obj):
self.objects.add(obj)
@ -146,10 +150,6 @@ class SeaClient(ProxyClient, Module):
self.path2param.setdefault(k, []).extend(v)
self.register_callback(module.name, module.updateEvent)
def startModule(self, start_events):
super().startModule(start_events)
self._connect_thread = mkthread(self._connect, start_events.get_trigger())
def _connect(self, started_callback):
self._last_connect = time.time()
if self._instance: