Skip to content

Commit d481569

Browse files
committed
coretasks: fix bad WHO tracking stuck in loop
`who_reqs` used to track `WHO` requests to the server flipped keys/values and was never getting cleared upon `RPL_ENDOFWHO`. Eventually, this would lead to an endless loop while the bot tried to get an unused "querytype" (`randint`) in order to track `WHO` replies. Now, key/values are in a more useful order (channel --map--> querytype). Also, the unneccessary loop used to ensure unique values for the query type was removed. A `RPL_WHOREPLY` includes the channel name in the response, so confirming that the querytype for a channel matched is sufficient. The same querytype could even be used for every channel without issue.
1 parent e2d8439 commit d481569

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

sopel/coretasks.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -702,9 +702,7 @@ def _send_who(bot, channel):
702702
# to identify the reply as one from this command, because if someone
703703
# else sent it, we have no fucking way to know what the format is.
704704
rand = str(randint(0, 999))
705-
while rand in who_reqs:
706-
rand = str(randint(0, 999))
707-
who_reqs[rand] = channel
705+
who_reqs[channel] = rand
708706
bot.write(['WHO', channel, 'a%nuachtf,' + rand])
709707
else:
710708
# We might be on an old network, but we still care about keeping our
@@ -1243,7 +1241,7 @@ def account_notify(bot, trigger):
12431241
@plugin.priority('medium')
12441242
def recv_whox(bot, trigger):
12451243
"""Track ``WHO`` responses when ``WHOX`` is enabled."""
1246-
if len(trigger.args) < 2 or trigger.args[1] not in who_reqs:
1244+
if len(trigger.args) < 2 or who_reqs.get(trigger.args[2]) is None:
12471245
# Ignored, some plugin probably called WHO
12481246
return
12491247
if len(trigger.args) != 8:
@@ -1314,7 +1312,9 @@ def recv_who(bot, trigger):
13141312
def end_who(bot, trigger):
13151313
"""Handle the end of a response to a ``WHO`` command (if needed)."""
13161314
if 'WHOX' in bot.isupport:
1317-
who_reqs.pop(trigger.args[1], None)
1315+
stored_querytype = who_reqs.pop(trigger.args[1], None)
1316+
if stored_querytype is None:
1317+
LOGGER.debug("Attempted to handle an untracked WHO reply for '%s'", trigger.args[1])
13181318

13191319

13201320
@module.event('AWAY')

0 commit comments

Comments
 (0)