memcached unix socket: fix panic. Do not recreate conn inside if

closes #841
This commit is contained in:
Cameron Sparr 2016-03-21 16:22:01 -06:00 committed by Michele Fadda
parent 87bdff4321
commit 37f93b4c44
2 changed files with 8 additions and 2 deletions

View File

@ -19,6 +19,7 @@
- [#898](https://github.com/influxdata/telegraf/issues/898): Put database name in quotes, fixes special characters in the database name. - [#898](https://github.com/influxdata/telegraf/issues/898): Put database name in quotes, fixes special characters in the database name.
- [#656](https://github.com/influxdata/telegraf/issues/656): No longer run `lsof` on linux to get netstat data, fixes permissions issue. - [#656](https://github.com/influxdata/telegraf/issues/656): No longer run `lsof` on linux to get netstat data, fixes permissions issue.
- [#907](https://github.com/influxdata/telegraf/issues/907): Fix prometheus invalid label/measurement name key. - [#907](https://github.com/influxdata/telegraf/issues/907): Fix prometheus invalid label/measurement name key.
- [#841](https://github.com/influxdata/telegraf/issues/841): Fix memcached unix socket panic.
## v0.11.1 [2016-03-17] ## v0.11.1 [2016-03-17]

View File

@ -94,14 +94,15 @@ func (m *Memcached) gatherServer(
acc telegraf.Accumulator, acc telegraf.Accumulator,
) error { ) error {
var conn net.Conn var conn net.Conn
var err error
if unix { if unix {
conn, err := net.DialTimeout("unix", address, defaultTimeout) conn, err = net.DialTimeout("unix", address, defaultTimeout)
if err != nil { if err != nil {
return err return err
} }
defer conn.Close() defer conn.Close()
} else { } else {
_, _, err := net.SplitHostPort(address) _, _, err = net.SplitHostPort(address)
if err != nil { if err != nil {
address = address + ":11211" address = address + ":11211"
} }
@ -113,6 +114,10 @@ func (m *Memcached) gatherServer(
defer conn.Close() defer conn.Close()
} }
if conn == nil {
return fmt.Errorf("Failed to create net connection")
}
// Extend connection // Extend connection
conn.SetDeadline(time.Now().Add(defaultTimeout)) conn.SetDeadline(time.Now().Add(defaultTimeout))