summaryrefslogtreecommitdiff
path: root/src/leap/bitmask/backend
diff options
context:
space:
mode:
authorKali Kaneko <kali@leap.se>2015-09-24 15:09:58 -0400
committerKali Kaneko <kali@leap.se>2015-09-24 15:09:58 -0400
commit08694af26b7b3d2e480c8379745dd5234315c87d (patch)
treeb38ce71cc7073bb573db97ca0dfc0c6ba0aa860f /src/leap/bitmask/backend
parentddc30afd194bb31a24cf5097fba8680721834b1f (diff)
parentaa31828fca8bb64ace56f6f3b2b94f90ffced3c2 (diff)
Merge tag '0.9.0rc3' into debian/experimental
Tag leap.bitmask version 0.9.0rc3
Diffstat (limited to 'src/leap/bitmask/backend')
-rw-r--r--src/leap/bitmask/backend/backend_proxy.py21
1 files changed, 14 insertions, 7 deletions
diff --git a/src/leap/bitmask/backend/backend_proxy.py b/src/leap/bitmask/backend/backend_proxy.py
index 30b7c5d1..ae300b32 100644
--- a/src/leap/bitmask/backend/backend_proxy.py
+++ b/src/leap/bitmask/backend/backend_proxy.py
@@ -27,8 +27,6 @@ import zmq
from zmq.eventloop import ioloop
from zmq.eventloop import zmqstream
-from taskthread import TimerTask
-
from leap.bitmask.backend.api import API, STOP_REQUEST, PING_REQUEST
from leap.bitmask.backend.settings import Settings
from leap.bitmask.backend.utils import generate_zmq_certificates_if_needed
@@ -141,7 +139,8 @@ class BackendProxy(object):
self._do_work = threading.Event()
self._work_lock = threading.Lock()
self._connection = ZmqREQConnection(self.SERVER, self._set_online)
- self._heartbeat = TimerTask(self._ping, delay=self.PING_INTERVAL)
+ self._heartbeat = threading.Timer(self.PING_INTERVAL,
+ self._heartbeat_loop)
self._ping_event = threading.Event()
self.online = False
self.settings = Settings()
@@ -197,17 +196,25 @@ class BackendProxy(object):
"""
with self._work_lock: # avoid sending after connection was closed
self._do_work.clear()
- self._heartbeat.stop()
+ self._heartbeat.cancel()
self._connection.stop()
logger.debug("BackendProxy worker stopped.")
- def _ping(self):
+ def _heartbeat_loop(self):
"""
- Heartbeat helper.
- Sends a PING request just to know that the server is alive.
+ Sends a PING request every PING_INTERVAL just to know that the server
+ is alive.
"""
self._send_request(PING_REQUEST)
+ # lets acquire the lock to prevent heartbeat timer to get cancel while
+ # we set a new one
+ with self._work_lock:
+ if self._do_work.is_set():
+ self._heartbeat = threading.Timer(self.PING_INTERVAL,
+ self._heartbeat_loop)
+ self._heartbeat.start()
+
def _api_call(self, *args, **kwargs):
"""
Call the `api_method` method in backend (through zmq).