Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[8.x] Apply shutdown timeout to http server to limit reload delay (backport #14339) #14362

Merged
merged 1 commit into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelogs/head.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ https://github.com/elastic/apm-server/compare/8.15\...main[View commits]

- Track all bulk request response status codes {pull}13574[13574]
- Fix a concurrent map write panic in monitoring middleware {pull}14335[14335]
- Apply shutdown timeout to http server {pull}14339[14339]

[float]
==== Breaking Changes
Expand Down
4 changes: 2 additions & 2 deletions internal/beater/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,9 @@ func (h *httpServer) start() error {
return h.Serve(h.httpListener)
}

func (h *httpServer) stop() {
func (h *httpServer) stop(ctx context.Context) {
h.logger.Infof("Stop listening on: %s", h.Server.Addr)
if err := h.Shutdown(context.Background()); err != nil {
if err := h.Shutdown(ctx); err != nil {
h.logger.Errorf("error stopping http server: %s", err.Error())
if err := h.Close(); err != nil {
h.logger.Errorf("error closing http server: %s", err.Error())
Expand Down
7 changes: 3 additions & 4 deletions internal/beater/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,11 +222,10 @@ func (s server) run(ctx context.Context) error {
})
g.Go(func() error {
<-ctx.Done()
// httpServer should stop before grpcServer to avoid a panic caused by placing a new connection into
// a closed grpc connection channel during shutdown.
// See https://github.com/elastic/gmux/issues/13
s.httpServer.stop()
s.grpcServer.GracefulStop()
stopctx, cancel := context.WithTimeout(context.Background(), s.cfg.ShutdownTimeout)
defer cancel()
s.httpServer.stop(stopctx)
return nil
})
if err := g.Wait(); err != http.ErrServerClosed {
Expand Down
Loading