Skip to content

Commit

Permalink
Actually disconnect on timeout
Browse files Browse the repository at this point in the history
Monitoring greenlets now commit suicide when
the connection is closed. This method prevents
the live_check_loop to kill its own greenlet
which prevented correct deregistration at the
server object before.
  • Loading branch information
Drahflow committed Apr 21, 2015
1 parent 24b8e1b commit cf3e737
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions lymph/core/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def set_status(self, status):
self.status = status

def heartbeat_loop(self):
while True:
while self.status != CLOSED:
start = time.monotonic()
channel = self.server.ping(self.endpoint)
try:
Expand All @@ -76,16 +76,22 @@ def heartbeat_loop(self):
gevent.sleep(self.heartbeat_interval)

def live_check_loop(self):
while True:
while self.status != CLOSED:
self.update_status()
self.log_stats()
gevent.sleep(self.timeout)

def update_status(self):
if self.last_seen:
now = time.monotonic()
if now - self.last_seen >= self.timeout:

if now - self.last_seen >= self.unresponsive_disconnect:
logger.debug("disconnecting from unresponsive endpoint %s" % (self.endpoint))
self.close()
elif now - self.last_seen >= self.timeout:
self.set_status(UNRESPONSIVE)
elif now - self.last_message >= self.idle_disconnect:
self.close()
elif now - self.last_message >= self.idle_timeout:
self.set_status(IDLE)
self.idle_since = now
Expand All @@ -108,8 +114,6 @@ def close(self):
if self.status == CLOSED:
return
self.status = CLOSED
self.heartbeat_loop_greenlet.kill()
self.live_check_loop_greenlet.kill()
self.server.disconnect(self.endpoint)

def on_recv(self, msg):
Expand Down

0 comments on commit cf3e737

Please sign in to comment.