From 010bb6a102daad1125ceb396aee08d2db45c9660 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ken-H=C3=A5vard=20Lieng?= Date: Tue, 5 May 2020 01:35:05 +0200 Subject: [PATCH] Sleep before first reconnect attempt --- pkg/irc/client.go | 3 +++ pkg/irc/conn.go | 1 + 2 files changed, 4 insertions(+) diff --git a/pkg/irc/client.go b/pkg/irc/client.go index 7e73d051..f6839f2e 100644 --- a/pkg/irc/client.go +++ b/pkg/irc/client.go @@ -6,6 +6,7 @@ import ( "net" "strings" "sync" + "time" "github.com/jpillora/backoff" ) @@ -54,6 +55,8 @@ func NewClient(nick, username string) *Client { reconnect: make(chan struct{}), recvBuf: make([]byte, 0, 4096), backoff: &backoff.Backoff{ + Min: 500 * time.Millisecond, + Max: 30 * time.Second, Jitter: true, }, } diff --git a/pkg/irc/conn.go b/pkg/irc/conn.go index 64339f06..935a55f4 100644 --- a/pkg/irc/conn.go +++ b/pkg/irc/conn.go @@ -79,6 +79,7 @@ func (c *Client) run() { c.sendRecv.Wait() c.reconnect = make(chan struct{}) + time.Sleep(c.backoff.Duration()) c.tryConnect() } }