Skip to content

Commit

Permalink
coretasks: fix bad WHO tracking stuck in loop
Browse files Browse the repository at this point in the history
`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.
  • Loading branch information
HumorBaby committed Jun 8, 2021
1 parent e2d8439 commit d481569
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions sopel/coretasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -702,9 +702,7 @@ def _send_who(bot, channel):
# to identify the reply as one from this command, because if someone
# else sent it, we have no fucking way to know what the format is.
rand = str(randint(0, 999))
while rand in who_reqs:
rand = str(randint(0, 999))
who_reqs[rand] = channel
who_reqs[channel] = rand
bot.write(['WHO', channel, 'a%nuachtf,' + rand])
else:
# We might be on an old network, but we still care about keeping our
Expand Down Expand Up @@ -1243,7 +1241,7 @@ def account_notify(bot, trigger):
@plugin.priority('medium')
def recv_whox(bot, trigger):
"""Track ``WHO`` responses when ``WHOX`` is enabled."""
if len(trigger.args) < 2 or trigger.args[1] not in who_reqs:
if len(trigger.args) < 2 or who_reqs.get(trigger.args[2]) is None:
# Ignored, some plugin probably called WHO
return
if len(trigger.args) != 8:
Expand Down Expand Up @@ -1314,7 +1312,9 @@ def recv_who(bot, trigger):
def end_who(bot, trigger):
"""Handle the end of a response to a ``WHO`` command (if needed)."""
if 'WHOX' in bot.isupport:
who_reqs.pop(trigger.args[1], None)
stored_querytype = who_reqs.pop(trigger.args[1], None)
if stored_querytype is None:
LOGGER.debug("Attempted to handle an untracked WHO reply for '%s'", trigger.args[1])


@module.event('AWAY')
Expand Down

0 comments on commit d481569

Please sign in to comment.