http: fix HTTP shutdown panicking

This commit is contained in:
Leo Balduf 2017-04-04 16:05:09 +02:00
parent ea1324602e
commit 2e625af44d
2 changed files with 6 additions and 7 deletions

View file

@ -124,7 +124,7 @@ func rootCmdRun(cmd *cobra.Command, args []string) error {
close(shutdown)
closed = true
} else {
log.Infoln(bufErr)
log.Errorln(bufErr)
}
bufErr = err
}
@ -175,7 +175,7 @@ func startFrontends(httpConfig httpfrontend.Config, udpConfig udpfrontend.Config
go func() {
log.Infoln("started serving HTTP on", httpConfig.Addr)
if err := httpFrontend.ListenAndServe(); err != nil {
errChan <- errors.New("failed to cleanly shutdown HTTP frontend: " + err.Error())
errChan <- err
}
}()
}
@ -186,7 +186,7 @@ func startFrontends(httpConfig httpfrontend.Config, udpConfig udpfrontend.Config
go func() {
log.Infoln("started serving UDP on", udpConfig.Addr)
if err := udpFrontend.ListenAndServe(); err != nil {
errChan <- errors.New("failed to cleanly shutdown UDP frontend: " + err.Error())
errChan <- err
}
}()
}

View file

@ -5,6 +5,7 @@ package http
import (
"context"
"crypto/tls"
"errors"
"net"
"net/http"
"time"
@ -144,10 +145,8 @@ func (t *Frontend) ListenAndServe() error {
}
// Start the HTTP server and gracefully handle any network errors.
if err := t.s.ListenAndServe(); err != nil {
if opErr, ok := err.(*net.OpError); !ok || (ok && opErr.Op != "accept") {
panic("http: failed to gracefully run HTTP server: " + err.Error())
}
if err := t.s.ListenAndServe(); err != nil && err != http.ErrServerClosed {
return errors.New("http: failed to run HTTP server: " + err.Error())
}
return nil