Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Actually disconnect on timeout #172

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This timeout should only apply once the connection status is UNRESPONSIVE.

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:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This timeout should only apply once the connection status is IDLE.

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