fix(sasl): add delay between mechanism attempts
When EXTERNAL fails and PLAIN is tried immediately, the server may not be ready. Add a 500ms delay before trying the next mechanism to give the server time to reset the authentication state. Changes: - Add asyncio import at top of file - Add _send_authenticate_after_delay() async method - Create delayed task when trying next mechanism - Remove inline asyncio import
This commit is contained in:
+10
-1
@@ -25,6 +25,7 @@ Features:
|
||||
- Abort support via AUTHENTICATE *
|
||||
"""
|
||||
|
||||
import asyncio
|
||||
import base64
|
||||
import hashlib
|
||||
import hmac
|
||||
@@ -1337,7 +1338,10 @@ class Sasl:
|
||||
self._username, self._password, self._selected_mechanism
|
||||
)
|
||||
|
||||
self.bot.send_line(f"AUTHENTICATE {self._selected_mechanism}")
|
||||
# Small delay before trying next mechanism to let server reset
|
||||
asyncio.get_event_loop().create_task(
|
||||
self._send_authenticate_after_delay(self._selected_mechanism)
|
||||
)
|
||||
else:
|
||||
self.bot.log.error("[SASL] No more mechanisms to try")
|
||||
self._authentication_in_progress = False
|
||||
@@ -1347,6 +1351,11 @@ class Sasl:
|
||||
else:
|
||||
self._finish_cap_negotiation()
|
||||
|
||||
async def _send_authenticate_after_delay(self, mechanism: str):
|
||||
"""Send AUTHENTICATE after a short delay."""
|
||||
await asyncio.sleep(0.5) # 500ms delay
|
||||
self.bot.send_line(f"AUTHENTICATE {mechanism}")
|
||||
|
||||
def _finish_cap_negotiation(self):
|
||||
"""Complete CAP negotiation by sending CAP END."""
|
||||
if self._cap_negotiation_complete:
|
||||
|
||||
Reference in New Issue
Block a user