From 568b84847b02d12f2e73fbd16fa0e1d946f54bd2 Mon Sep 17 00:00:00 2001 From: Valentin Lorentz Date: Mon, 18 May 2020 20:50:14 +0200 Subject: [PATCH] irclib: Fix hang in cap nego when echo-message is available but not labeled-response. echo-message ended up in self.state.capabilities_req even though it wasn't requested, so the bot was stuck in state: "Waiting for ACK/NAK of capabilities: {'echo-message'}". --- src/irclib.py | 5 +++-- test/test_irclib.py | 7 +++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/irclib.py b/src/irclib.py index 130f98e43..334a5a024 100644 --- a/src/irclib.py +++ b/src/irclib.py @@ -1682,8 +1682,6 @@ class Irc(IrcCommandDispatcher, log.Firewalled): self._requestCaps(common_supported_unrequested_capabilities) def _requestCaps(self, caps): - self.state.capabilities_req |= caps - caps = list(sorted(caps)) cap_lines = [] if 'echo-message' in caps \ @@ -1701,6 +1699,9 @@ class Irc(IrcCommandDispatcher, log.Firewalled): # This makes sure they are always on the same line (which # happens to be the first): caps = ['echo-message', 'labeled-response'] + caps + + self.state.capabilities_req |= set(caps) + caps = ' '.join(caps) # textwrap works here because in ASCII, all chars are 1 bytes: cap_lines = textwrap.wrap( diff --git a/test/test_irclib.py b/test/test_irclib.py index 04fb954ec..da216c210 100644 --- a/test/test_irclib.py +++ b/test/test_irclib.py @@ -522,6 +522,13 @@ class IrcCapsTestCase(SupyTestCase): m = self.irc.takeMsg() self.assertIsNone(m) + self.irc.feedMsg(ircmsgs.IrcMsg(command='CAP', + args=('*', 'ACK', 'account-notify'))) + + m = self.irc.takeMsg() + self.assertTrue(m.command == 'CAP', 'Expected CAP, got %r.' % m) + self.assertEqual(m.args, ('END',), m) + def testEchomessageLabeledresponseGrouped(self): self.irc = irclib.Irc('test')