From 8927f5c9355ce0b819161474869e15a87279d2b0 Mon Sep 17 00:00:00 2001 From: Trygve Aaberge Date: Fri, 3 May 2019 15:50:39 +0200 Subject: 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. --- wee_slack.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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 -- cgit