fix: cp.Mux.Serve() closes all net.Listener instances silently on error. (#20278)

A customer has seen a rash of "connection refused" errors to the meta node.
This fix ensures that when net.Listener instances are closed because of an
error in Accept(), influxdb logs the error which caused the closures, as well
as any errors in closing the Listeners.

Fixes https://github.com/influxdata/influxdb/issues/20256
pull/20388/head
davidby-influx 2020-12-08 16:17:59 -08:00 committed by GitHub
parent 6ac0bb3fe3
commit 5b98166b05
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 3 deletions

View File

@ -79,6 +79,7 @@ func (mux *Mux) Serve(ln net.Listener) error {
continue
}
if err != nil {
mux.Logger.Printf("tcp.Mux: Listener at %s failed failed to accept a connection, closing all listeners - %s", ln.Addr(), err)
// Wait for all connections to be demux
mux.wg.Wait()
@ -90,7 +91,9 @@ func (mux *Mux) Serve(ln net.Listener) error {
wg.Add(1)
go func(ln *listener) {
defer wg.Done()
ln.Close()
if err := ln.Close(); err != nil {
mux.Logger.Printf("tcp.Mux: Closing the listener at %s failed - %s", ln.Addr().String(), err)
}
}(ln)
}
mux.mu.RUnlock()
@ -100,9 +103,10 @@ func (mux *Mux) Serve(ln net.Listener) error {
dl := mux.defaultListener
mux.mu.RUnlock()
if dl != nil {
dl.Close()
if closeErr := dl.Close(); closeErr != nil {
mux.Logger.Printf("tcp.Mux: Closing the default listener at %s failed - %s", ln.Addr().String(), closeErr)
}
}
return err
}