Skip to content

Commit

Permalink
Different timeout semantics as per @emulbreh
Browse files Browse the repository at this point in the history
  • Loading branch information
Drahflow committed Apr 24, 2015
1 parent 3584433 commit c9391d5
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions lymph/core/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ def __init__(self, server, endpoint, heartbeat_interval=1, timeout=1, idle_timeo

now = time.monotonic()
self.last_seen = 0
self.idle_since = 0
self.last_message = now
self.created_at = now
self.heartbeat_samples = SampleWindow(100, factor=1000) # milliseconds
self.explicit_heartbeat_count = 0
self.status = UNKNOWN
self.last_status_change = now

self.received_message_count = 0
self.sent_message_count = 0
Expand All @@ -60,6 +60,9 @@ def phi(self):
return -math.log10(p)

def set_status(self, status):
if status != self.status:
self.last_status_change = time.monotonic()

self.status = status

def heartbeat_loop(self):
Expand All @@ -85,16 +88,15 @@ def update_status(self):
if self.last_seen:
now = time.monotonic()

if now - self.last_seen >= self.unresponsive_disconnect:
if self.status == UNRESPONSIVE and now - self.last_status_change >= 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:
elif self.status == IDLE and now - self.last_status_change >= self.idle_disconnect:
self.close()
elif now - self.last_message >= self.idle_timeout:
self.set_status(IDLE)
self.idle_since = now
else:
self.set_status(RESPONSIVE)

Expand Down

0 comments on commit c9391d5

Please sign in to comment.