Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
9 changes: 8 additions & 1 deletion statsd/pipe_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,14 @@ func (p *pipeWriter) ensureConnection() (net.Conn, error) {
}

func (p *pipeWriter) Close() error {
return p.conn.Close()
p.mu.RLock()
conn := p.conn
p.mu.RUnlock()
// conn is nil if no write ever established a connection
if conn != nil {
return conn.Close()
}
return nil
Comment thread
mrafi97 marked this conversation as resolved.
Outdated
}

// GetTransportName returns the name of the transport
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