diff --git a/client.go b/client.go index 3969c0d..8984eeb 100644 --- a/client.go +++ b/client.go @@ -59,6 +59,7 @@ type StatsdClient struct { prefix string sockType socketType Logger Logger + reconnect bool reconnect_ticker *time.Ticker } @@ -70,14 +71,17 @@ func NewStatsdClient(addr string, prefix string) *StatsdClient { addr: addr, prefix: prefix, Logger: log.New(os.Stdout, "[StatsdClient] ", log.Ldate|log.Ltime), + reconnect: false, reconnect_ticker: time.NewTicker(30 * time.Second), } go func() { for range client.reconnect_ticker.C { - err := client.Reconnect() - if err != nil { - fmt.Println(err) + if client.reconnect { + err := client.Reconnect() + if err != nil { + fmt.Println(err) + } } } }() diff --git a/client_test.go b/client_test.go index 3c662ea..8d4988d 100644 --- a/client_test.go +++ b/client_test.go @@ -622,6 +622,7 @@ func TestReconnecting(t *testing.T) { prefix := "test." client := NewStatsdClient(udpAddr.String(), prefix) + client.reconnect = true client.reconnect_ticker = time.NewTicker(10 * time.Millisecond) ch := make(chan string, 0)