Skip to content

Commit 7533804

Browse files
committed
fix: wait for JOIN confirmations concurrently to avoid missed 366 replies
The sequential wait_for loop would miss the 366 (RPL_ENDOFNAMES) for later channels because their replies arrived while still waiting on the first channel.
1 parent b20c5d8 commit 7533804

2 files changed

Lines changed: 19 additions & 8 deletions

File tree

irc_handlers/err_nomotd_422.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import asyncio
12
import logging
23

34
ID = "422"
@@ -10,14 +11,19 @@ async def execute(self, send_msg, prefix, command, params):
1011
logger.info("No MOTD (422), starting post-connection setup")
1112
await self.join_channel(send_msg, self.channels)
1213

13-
for chan in self.channels:
14-
try:
15-
await self.wait_for(
14+
results = await asyncio.gather(
15+
*(
16+
self.wait_for(
1617
"366",
1718
check=lambda p, c, params, ch=chan: ch.lower() in params.lower(),
1819
timeout=30,
1920
)
20-
except TimeoutError:
21+
for chan in self.channels
22+
),
23+
return_exceptions=True,
24+
)
25+
for chan, result in zip(self.channels, results):
26+
if isinstance(result, TimeoutError):
2127
logger.warning("Timed out waiting for JOIN confirmation on %s", chan)
2228

2329
await send_msg("MODE " + ",".join(self.channels), 4)

irc_handlers/rpl_endofmotd_376.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,19 @@ async def execute(self, send_msg, prefix, command, params):
1111
logger.info("End of MOTD, starting post-connection setup")
1212
await self.join_channel(send_msg, self.channels)
1313

14-
for chan in self.channels:
15-
try:
16-
await self.wait_for(
14+
results = await asyncio.gather(
15+
*(
16+
self.wait_for(
1717
"366",
1818
check=lambda p, c, params, ch=chan: ch.lower() in params.lower(),
1919
timeout=30,
2020
)
21-
except TimeoutError:
21+
for chan in self.channels
22+
),
23+
return_exceptions=True,
24+
)
25+
for chan, result in zip(self.channels, results):
26+
if isinstance(result, TimeoutError):
2227
logger.warning("Timed out waiting for JOIN confirmation on %s", chan)
2328

2429
await send_msg("MODE " + ",".join(self.channels), 4)

0 commit comments

Comments
 (0)