nickvanw / ircx

Basic callback-driven Go IRC bot

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Disconnects on read error

mvdan opened this issue · comments

Before the logs were removed, it showed this before dying:

2015/08/21 02:37:28 Error: read tcp 193.219.128.49:6667: i/o timeout

Now it just dies, as expected.

This is when connected to freenode. This is when using HandleLoop like in the example code.

I suggest one of two options:

  • Have HandleLoop silently take care of this, either by ignoring the error or by reconnecting. Not sure if a reconnection is necessary.
  • Change the behaviour of HandleLoop so that it returns error, and makes us decide to re-run it if we wish to, e.g.:
for {
    err := b.HandleLoop()
    log.Printf("HandleLoop exited: %v", err)
}

(assuming no reconnect is required)

Hi @mvdan

Upon disconnection, ReadLoop will attempt to reconnect if it's configured to: https://github.com/nickvanw/ircx/blob/master/bot.go#L116

By setting the MaxRetries to anything above 0, it will automatically reconnect when there is a read error.

I think adding an error return to HandleLoop may be a good additional step, thoughts?

I see, hadn't noticed you could configure MaxRetries. That works for me, as I don't need a stricter control over disconnects and retries.

Sure, HandleLoop could return an error.

So I wasn't closing this issue because I was getting send errors after a reconnet.

Reason: I'm an idiot. This was happening because I had a pointer to Sender, not to Bot. So on Reconnect(), when it called Connect() again, it would create a new Sender. I would get stuck with the old sender, which had a disonnected tcp connection.