Handle badly encoded incoming messages better

This commit is contained in:
Ondrej Mikle 2023-10-03 19:45:36 +02:00
parent 30ca988239
commit b496da75c5

View file

@ -355,13 +355,18 @@ class IrcThread(threading.Thread):
# see https://github.com/jaraco/irc/issues/132 # see https://github.com/jaraco/irc/issues/132
while self.getConnected(): while self.getConnected():
self.reactor.process_once(timeout=5)
try: try:
with self.threadLock: self.reactor.process_once(timeout=5)
msg = self.msgQueue.get_nowait() try:
self.connection.privmsg_many(self.channels, msg) with self.threadLock:
except Queue.Empty: msg = self.msgQueue.get_nowait()
pass self.connection.privmsg_many(self.channels, msg)
except Queue.Empty:
pass
except UnicodeDecodeError:
logging.warn("Skipped incorrectly encoded message, cannot decode to UTF-8")
except UnicodeEncodeError:
logging.warn("We were sending badly encoded message? maybe via topic?")
except Exception: except Exception:
logging.exception("Exception in IRC thread") logging.exception("Exception in IRC thread")
time.sleep(self.reconnectDelay) time.sleep(self.reconnectDelay)