aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTrygve Aaberge <trygveaa@gmail.com>2019-04-22 20:48:20 +0200
committerTrygve Aaberge <trygveaa@gmail.com>2019-04-23 10:56:42 +0200
commit6aafb4620fb4407190c4a7c02bdc26f20546c83f (patch)
treee110c418addd739e79f8158acdcff5755e470e13
parentcea09f871b52b72909cff733c97dd8e507d2fa5b (diff)
downloadwee-slack-6aafb4620fb4407190c4a7c02bdc26f20546c83f.tar.gz
Don't connect to rtm multiple times simultaneously
-rw-r--r--wee_slack.py20
1 files changed, 11 insertions, 9 deletions
diff --git a/wee_slack.py b/wee_slack.py
index a4debc0..abe24bb 100644
--- a/wee_slack.py
+++ b/wee_slack.py
@@ -1095,7 +1095,8 @@ class SlackTeam(object):
self.identifier = team_info["id"]
self.ws_url = websocket_url
self.connected = False
- self.connecting = False
+ self.connecting_rtm = False
+ self.connecting_ws = False
self.ws = None
self.ws_counter = 0
self.ws_replies = {}
@@ -1246,9 +1247,9 @@ class SlackTeam(object):
pass
def connect(self):
- if not self.connected and not self.connecting:
- self.connecting = True
+ if not self.connected and not self.connecting_ws:
if self.ws_url:
+ self.connecting_ws = True
try:
# only http proxy is currently supported
proxy = ProxyWrapper()
@@ -1260,24 +1261,23 @@ class SlackTeam(object):
self.hook = w.hook_fd(ws.sock.fileno(), 1, 0, 0, "receive_ws_callback", self.get_team_hash())
ws.sock.setblocking(0)
self.ws = ws
- # self.attach_websocket(ws)
+ self.set_reconnect_url(None)
self.set_connected()
- self.connecting = False
+ self.connecting_ws = False
except:
w.prnt(self.channel_buffer,
'Failed connecting to slack team {}, retrying.'.format(self.domain))
dbg('connect failed with exception:\n{}'.format(format_exc_tb()), level=5)
- self.connecting = False
+ self.connecting_ws = False
return False
- else:
+ elif not self.connecting_rtm:
# The fast reconnect failed, so start over-ish
for chan in self.channels:
self.channels[chan].got_history = False
s = initiate_connection(self.token, retries=999, team_hash=self.team_hash)
self.eventrouter.receive(s)
- self.connecting = False
+ self.connecting_rtm = True
# del self.eventrouter.teams[self.get_team_hash()]
- self.set_reconnect_url(None)
def set_connected(self):
self.connected = True
@@ -2518,12 +2518,14 @@ def handle_rtmstart(login_data, eventrouter):
else:
t = eventrouter.teams.get(th)
t.set_reconnect_url(login_data['url'])
+ t.connecting_rtm = False
t.connect()
def handle_rtmconnect(login_data, eventrouter):
metadata = login_data["wee_slack_request_metadata"]
team = eventrouter.teams.get(metadata.team_hash)
+ team.connecting_rtm = False
if not login_data["ok"]:
w.prnt("", "ERROR: Failed reconnecting to Slack with token starting with {}: {}"