IRC Bot disconnects with EOF unless it joins its own channel

I’m writing a twitch bot in golang that joins one or more channels and replies to simple FAQ commands for each channel.

During development I’ve stumbled upon this weird issue where my bot would randomly disconnect with an EOF error after a few minutes, and I have realized that making it also join its own channel fixes it. (for example, if the bot was running on the account shigebot, making it join #shigebot plus the other channels it should operate on fixes the disconnections).

Increasing the ping rate makes the disconnection quicker. And yes, I am also replying to twitch PINGs.
This happens regardless of chat activity (still disconnects even if the chat is active the entire time).

It is not a huge issue for me because it can be easily solved as I just explained, but is this expected behaviour or am I doing something wrong?

No, this is not expected behaviour. Most likely there is something wrong in your code. Perhaps you handle being in your own channel differently than being in others.

If you can’t find it yourself, post relevant code here and maybe I or someone else here can help. By the way you only need to send a PONG when you’ve received a PING.

Automatically reconnecting is not a bad idea regardless of your issues, this would look something like:

if str, err = reader.ReadString('\n'); err != nil {
    if err == io.EOF {
        //rejoin previous channels
1 Like

Yes, I’m only sending PONGs when I receive a PING.

However I’m using this library
which seems to send ‘PING timestamp’ to the server here
(which is what I was referring to when I said ping rate).

Could it be that twitch servers do not support these pings?
I am not handling anything differently for my own channel, by the way.

This is the core of my irc handling (note that SendRawf appends \r\n automatically:

EDIT: I just noticed that the ircevent library already handles PING internally by replying with PONG :server , but the disconnection issue was there even before I added my own PING handler.

tmi does not entirely adhere to the IRC standard, and as far as I know do not handle incoming PING’s. Only PONG [server] as a response to PING.

I could not see where the library responds with PONG’s, but I believe your problem is that you are disconnected when the library attempts to PING.

Either make it timeout after a very long time or scrap the library entirely. I made mine from scratch, and it’s not that hard tbh.

1 Like

Here are some of the parts of my old project, free to use, no license or whatnot.



This is basically how you can use it:

I rewrote the last part just now, so I can’t guarantee it will work of the bat. But take what you like.

1 Like

Thank you, I am currently testing for disconnects after disabling the pings for ircevent by using a huge ping delay. If it doesn’t work out i’ll just write a library based off yours.

1 Like

For what it’s worth, I use go-ircevent in both a bot and a desktop client (with the built-in ping handling) and have not encountered the issue you mention. It would seem that there’s something else afoot in your code.

1 Like

Well, seems like the issue is resolved after disabling the built-in ping. However, since Carl said the builtin ping causes no issues for him, it could have very well been twitch somehow mistaking my bot for a spambot and dropping the connection. Now that i think about it I had started experiencing these issues only after switching the bot to its own newly created twitch account instead of my own.

Thanks everyone for the help, the bot has been up for 12+ hours now with no disconnects and without joining its own channel.

It replies to PING with PONG and PING :something with PONG :something. It’s how I measure my connection latency to the chat servers, and not replying to them would break compatibility with some clients.

Good to know, OPs original problem just keep getting more mysterious. If they return, a communication log would be interesting.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.