From b9482be72fe856ec5663f35bd7e78cea1e2a5d11 Mon Sep 17 00:00:00 2001 From: Zdenek Styblik Date: Wed, 8 Jun 2016 11:04:04 +0200 Subject: [PATCH 1/2] Remove "quick listener check" and don't mute connection Commit removes "quick listener check" which mutes connection and returns error when listener isn't available at the time of inicialization. It seems as this there is no need to scrap connection, because when remote endpoint comes around later, metrics will be received by that endpoint just fine. Fixes #6 --- conn.go | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/conn.go b/conn.go index 4dbda63..8681912 100644 --- a/conn.go +++ b/conn.go @@ -45,18 +45,6 @@ func newConn(conf connConfig, muted bool) (*conn, error) { if err != nil { return c, err } - // When using UDP do a quick check to see if something is listening on the - // given port to return an error as soon as possible. - if c.network[:3] == "udp" { - for i := 0; i < 2; i++ { - _, err = c.w.Write(nil) - if err != nil { - _ = c.w.Close() - c.w = nil - return c, err - } - } - } // To prevent a buffer overflow add some capacity to the buffer to allow for // an additional metric. From 0da27f56acee26cf67b824f8062120bf53c52152 Mon Sep 17 00:00:00 2001 From: Christian Blades Date: Tue, 13 Sep 2016 23:39:22 -0400 Subject: [PATCH 2/2] fix tests for expected behavior * non-listening ports should not cause statsd client to mute --- statsd_test.go | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/statsd_test.go b/statsd_test.go index c97650c..edbc2d8 100644 --- a/statsd_test.go +++ b/statsd_test.go @@ -336,10 +336,7 @@ func TestDialError(t *testing.T) { } defer func() { dialTimeout = net.DialTimeout }() - c, err := New() - if c == nil || !c.muted { - t.Error("New() did not return a muted client") - } + _, err := New() if err == nil { t.Error("New() did not return an error") } @@ -364,11 +361,11 @@ func TestUDPNotListening(t *testing.T) { defer func() { dialTimeout = net.DialTimeout }() c, err := New() - if c == nil || !c.muted { - t.Error("New() did not return a muted client") + if c.muted { + t.Error("client should not mute when attempting to connect to a non-listening port") } - if err == nil { - t.Error("New should return an error") + if err != nil { + t.Error("attempting to connect to a non-listening port should not return an error") } }