Page MenuHomePhabricator

tcpircbot shouldn't crash if it receives a message with a newline
Open, Needs TriagePublic

Description

During a scap backport, logmsgbot crashed, with this in the logs:

Sep 16 22:52:44 alert1002 tcpircbot-logmsgbot[1538207]: @cee: {"ecs.version": "1.7.0", "log.level": "INFO", "log.origin.file.line": 216, "log.origin.file.name": "tcpircbot.py", "log.origin.file.path": "/srv/tcpircbot/tcpircbot.py", "log.origin.function": "<module>", "message": "TCP ('::ffff:10.64.16.93', 40550, 0, 0): \"!log rzl@deploy1003 sync-world failed: <HelmfileError> Could not read the state of the releases of:\n /srv/deployment-charts/helmfile.d/dse-k8s-services/mediawiki-dumps-legacy in dse-k8s-eqiad: Could not list the releases: (cd /srv/deployment-charts/helmfile.d/dse-k8s-services/mediawiki-dumps-legacy && helm --kubeconfig /etc/kubernetes/mediawiki-dumps-legacy-deploy-dse-k8s-eqiad.config ls -a -o json --max=1000) (scap versi\"", "process.name": "MainProcess", "process.thread.id": 1538207, "process.thread.name": "MainThread", "timestamp": "2026-09-16T22:52:44.845824"}
Sep 16 22:52:44 alert1002 tcpircbot-logmsgbot[1538207]: @cee: {"ecs.version": "1.7.0", "log.level": "ERROR", "log.origin.file.line": 88, "log.origin.file.name": "tcpircbot.py", "log.origin.file.path": "/srv/tcpircbot/tcpircbot.py", "log.origin.function": "log_unhandled_exception", "message": "Unhandled exception: Carriage returns not allowed in privmsg(text)", "process.name": "MainProcess", "process.thread.id": 1538207, "process.thread.name": "MainThread", "timestamp": "2026-09-16T22:52:44.846083", "error.stack_trace": "Traceback (most recent call last):\n  File \"/srv/tcpircbot/tcpircbot.py\", line 218, in <module>\n    bot.connection.privmsg(channel, data)\n  File \"/usr/lib/python3/dist-packages/irc/client.py\", line 854, in privmsg\n    self.send_raw(\"PRIVMSG %s :%s\" % (target, text))\n  File \"/usr/lib/python3/dist-packages/irc/client.py\", line 875, in send_raw\n    raise InvalidCharacters(\nirc.client.InvalidCharacters: Carriage returns not allowed in privmsg(text)"}

The attempted message had a newline in it, which obviously isn't allowed on IRC, so scap shouldn't have attempted to send it -- but tcpircbot should handle that more gracefully. At the very least it should catch the exception and discard the offending message instead of crashing, but in the case of a newline, it should just replace it with a space before sending.

Event Timeline

Change #1342704 had a related patch set uploaded (by Tiziano Fogli; author: Tiziano Fogli):

[operations/puppet@production] tcpircbot: replace newlines with spaces on privmsg

https://gerrit.wikimedia.org/r/1342704

ayounsi edited projects, added: Observability-Alerting; removed: SRE.
ayounsi subscribed.

[clinic duty] boldly assigning the task to Tiziano as they sent a patch.

Change #1342704 merged by Tiziano Fogli:

[operations/puppet@production] tcpircbot: replace newlines with spaces in PRIVMSG

https://gerrit.wikimedia.org/r/1342704