diff options
author | Trygve Aaberge <trygveaa@gmail.com> | 2019-05-03 15:50:39 +0200 |
---|---|---|
committer | Trygve Aaberge <trygveaa@gmail.com> | 2019-05-03 15:50:39 +0200 |
commit | 8927f5c9355ce0b819161474869e15a87279d2b0 (patch) | |
tree | d971cc7cfb2a7497710423dfb05e9c0b0e504574 | |
parent | f3d880e3f3a761c65f47d3f39de9c03bc5370e96 (diff) | |
download | wee-slack-8927f5c9355ce0b819161474869e15a87279d2b0.tar.gz |
Only check for pong responses when ping has been recently sent
With large teams on a slow computer, wee-slack may unfortunately hang
for a while at times while processing data. When this happen, it doesn't
get a chance to send pings. When it's finished processing, it previously
might have disconnected if the pong checker runs before sending a ping,
since it's a long time since a ping has been sent.
-rw-r--r-- | wee_slack.py | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/wee_slack.py b/wee_slack.py index 4c6269d..6482283 100644 --- a/wee_slack.py +++ b/wee_slack.py @@ -401,7 +401,9 @@ class EventRouter(object): def reconnect_if_disconnected(self): for team in self.teams.values(): - if team.connected and time.time() - team.last_pong_time > 12: + time_since_last_ping = time.time() - team.last_ping_time + time_since_last_pong = time.time() - team.last_pong_time + if team.connected and time_since_last_ping < 5 and time_since_last_pong > 12: w.prnt(team.channel_buffer, 'Lost connection to slack team {} (no pong), reconnecting.'.format( team.domain)) @@ -725,6 +727,7 @@ def ws_ping_cb(data, remaining_calls): if team.ws and team.connected: try: team.ws.ping() + team.last_ping_time = time.time() except (WebSocketConnectionClosedException, socket.error) as e: handle_socket_error(e, team, 'ping') return w.WEECHAT_RC_OK @@ -1112,6 +1115,7 @@ class SlackTeam(object): self.ws = None self.ws_counter = 0 self.ws_replies = {} + self.last_ping_time = 0 self.last_pong_time = time.time() self.eventrouter = eventrouter self.token = token |