Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

don't mute connection when listener is absent #8

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 0 additions & 12 deletions conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
13 changes: 5 additions & 8 deletions statsd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand All @@ -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")
}
}

Expand Down