fix(inputs.statsd): On close, verify listener is not nil (#12778)

This commit is contained in:
Joshua Powers 2023-03-03 06:45:33 -07:00 committed by GitHub
parent e2a510f157
commit dfe8b43e20
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 2 deletions

View File

@ -944,9 +944,14 @@ func (s *Statsd) Stop() {
s.Log.Infof("Stopping the statsd service")
close(s.done)
if s.isUDP() {
s.UDPlistener.Close() //nolint:revive // Ignore the returned error as we cannot do anything about it anyway
if s.UDPlistener != nil {
s.UDPlistener.Close() //nolint:revive // Ignore the returned error as we cannot do anything about it anyway
}
} else {
s.TCPlistener.Close() //nolint:revive // Ignore the returned error as we cannot do anything about it anyway
if s.TCPlistener != nil {
s.TCPlistener.Close() //nolint:revive // Ignore the returned error as we cannot do anything about it anyway
}
// Close all open TCP connections
// - get all conns from the s.conns map and put into slice
// - this is so the forget() function doesnt conflict with looping