Skip to content

Commit

Permalink
http: shutdown the actual http server (#1689)
Browse files Browse the repository at this point in the history
PR #1680 introduced graceful handling for the HTTP server in Thanos, but
the graceful `Shutdown` call was being performed on an `http.Server`
instance that was *not* running at all. The actual server that was
listening for requests was started through `http.Serve`, so there was no
reference to the server struct that we could use to shut it down. This
was causing all of Thanos to freeze after receiving an exit signal,
because the run-group for the HTTP server would never finalize.

This seems like an oversight because the `(*Server).srv` field was being
properly initialized with an HTTP server. Fix this by calling
`ListenAndServe` on our initialized server.

Signed-off-by: Vicent Marti <[email protected]>
Signed-off-by: Giedrius Statkevičius <[email protected]>
  • Loading branch information
Vicent Martí authored and GiedriusS committed Oct 28, 2019
1 parent a88dd7c commit 19b0c5d
Showing 1 changed file with 3 additions and 11 deletions.
14 changes: 3 additions & 11 deletions pkg/server/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package server

import (
"context"
"net"
"net/http"
"net/http/pprof"
"time"
Expand All @@ -22,9 +21,8 @@ type Server struct {
comp component.Component
prober *prober.Prober

mux *http.ServeMux
srv *http.Server
listener net.Listener
mux *http.ServeMux
srv *http.Server

opts options
}
Expand Down Expand Up @@ -55,15 +53,9 @@ func NewHTTP(logger log.Logger, reg *prometheus.Registry, comp component.Compone
}

func (s *Server) ListenAndServe() error {
l, err := net.Listen("tcp", s.opts.listen)
if err != nil {
return errors.Wrap(err, "listen metrics address")
}
s.listener = l
s.prober.SetHealthy()
level.Info(s.logger).Log("msg", "listening for requests and metrics", "component", s.comp.String(), "address", s.opts.listen)

return errors.Wrapf(http.Serve(l, s.mux), "serve %s and metrics", s.comp.String())
return errors.Wrapf(s.srv.ListenAndServe(), "serve %s and metrics", s.comp.String())
}

func (s *Server) Shutdown(err error) {
Expand Down

0 comments on commit 19b0c5d

Please sign in to comment.