Skip to content
Merged
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
7 changes: 7 additions & 0 deletions statsd/pipe_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,13 @@ func (p *pipeWriter) ensureConnection() (net.Conn, error) {
}

func (p *pipeWriter) Close() error {
p.mu.RLock()
defer p.mu.RUnlock()
// conn is nil if no write ever established a connection
if p.conn == nil {
return nil
}

return p.conn.Close()
}

Expand Down
13 changes: 13 additions & 0 deletions statsd/pipe_windows_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,19 @@ func TestPipeWriterEnv(t *testing.T) {
assert.Equal(t, got, "metric:1|g|#key:val\n")
}

// TestPipeWriterCloseWithoutWrite ensures closing a writer that never
// established a connection does not panic. newWindowsPipeWriter defers
// connecting to the first write, so conn is nil until then.
func TestPipeWriterCloseWithoutWrite(t *testing.T) {
pipepath, f, _ := createNamedPipe(t)
defer os.Remove(f.Name())

w, err := newWindowsPipeWriter(pipepath, defaultWriteTimeout)
require.Nil(t, err)

assert.Nil(t, w.Close())
}

func TestPipeWriterReconnect(t *testing.T) {
pipepath, f, ln := createNamedPipe(t)
defer os.Remove(f.Name())
Expand Down
Loading