bot: fix duplicate unregister KeyError and improve connection error logging
All checks were successful
continuous-integration/drone/push Build is passing

Silently ignore KeyError when unregistering an already-removed FD from
the poll loop (servers can queue multiple close events). Also include
the exception message when a server connection fails at startup.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
nemunaire 2026-03-06 22:14:20 +07:00
commit 310f933091
2 changed files with 6 additions and 3 deletions

View file

@ -163,8 +163,8 @@ def main():
logger.info("Server '%s' successfully added.", srv.name)
else:
logger.error("Can't add server '%s'.", srv.name)
except:
logger.error("Unable to connect to '%s'.", srv.name)
except Exception as e:
logger.error("Unable to connect to '%s': %s", srv.name, e)
continue
break

View file

@ -218,7 +218,10 @@ class Bot(threading.Thread):
elif args[0] == "register":
self._poll.register(int(args[1]), select.POLLIN | select.POLLPRI)
elif args[0] == "unregister":
self._poll.unregister(int(args[1]))
try:
self._poll.unregister(int(args[1]))
except KeyError:
pass
except:
logger.exception("Unhandled excpetion during action:")