Skip to content

Commit

Permalink
fix close on closed socket_writer (influxdata#2748)
Browse files Browse the repository at this point in the history
  • Loading branch information
phemmer authored and danielnelson committed May 2, 2017
1 parent 5c88965 commit 52c19af
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
10 changes: 10 additions & 0 deletions plugins/outputs/socket_writer/socket_writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,16 @@ func (sw *SocketWriter) Write(metrics []telegraf.Metric) error {
return nil
}

// Close closes the connection. Noop if already closed.
func (sw *SocketWriter) Close() error {
if sw.Conn == nil {
return nil
}
err := sw.Conn.Close()
sw.Conn = nil
return err
}

func newSocketWriter() *SocketWriter {
s, _ := serializers.NewInfluxSerializer()
return &SocketWriter{
Expand Down
2 changes: 1 addition & 1 deletion plugins/outputs/socket_writer/socket_writer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ func TestSocketWriter_Write_err(t *testing.T) {

// close the socket to generate an error
lconn.Close()
sw.Close()
sw.Conn.Close()
err = sw.Write(metrics)
require.Error(t, err)
assert.Nil(t, sw.Conn)
Expand Down

0 comments on commit 52c19af

Please sign in to comment.