Skip to content

Commit

Permalink
Merge pull request #61 from kmille/master
Browse files Browse the repository at this point in the history
Improve handling of connection issues 1/
  • Loading branch information
fleaz committed Mar 11, 2021
2 parents 4a39ac1 + f0faa6e commit 8fca0bc
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
6 changes: 3 additions & 3 deletions cpthook.yml.example
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ logging:
level: "INFO"

irc:
host: "irc.hackint.eu"
port: 6667
host: "irc.hackint.org"
port: 6697
ssl:
enabled: true
cafile: "/etc/ssl/hackint.pem"
cafile: "/etc/ssl/certs/ca-certificates.crt"
client_cert:
certfile: "/home/bot/bot.cert"
keyfile: "/home/bot/bot.key"
Expand Down
16 changes: 10 additions & 6 deletions irc.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,16 @@ func ircConnection(config *viper.Viper, channelList []string) {

log.Info("Connecting to IRC server")
for {
if err := client.Connect(); err != nil {
clientLock.Lock()
log.Warnf("Connection to %s terminated: %s", client.Server(), err)
log.Warn("Reconnecting in 30 seconds...")
time.Sleep(30 * time.Second)
}
// client.Connect() blocks. It returns nil if we call a client.Close() which we never do.
// If the the connection is dropped/broken (recognized if we don't get a PONG 60 seconds
// after we sent a PING) an error is returned.
err := client.Connect()
// FIXME: if client.Connect() fails twice without going in state connected our handler is
// not called. This means that the lock is still acquired and we will hang here forever.
clientLock.Lock()
log.Warnf("Connection terminated: %s", err)
log.Warn("Reconnecting in 30 seconds...")
time.Sleep(30 * time.Second)
}

}
Expand Down

0 comments on commit 8fca0bc

Please sign in to comment.