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

Apply shutdown timeout to http server to limit reload delay #14339

Merged
merged 5 commits into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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 @@ -7,6 +7,7 @@ https://github.com/elastic/apm-server/compare/8.15\...main[View commits]
==== Bug fixes

- Track all bulk request response status codes {pull}13574[13574]
- 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()
Copy link
Member Author

@carsonip carsonip Oct 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[to reviewer] Moving grpcServer.GracefulStop ahead of httpServer.stop, as this was how the code was originally written before elastic/gmux#13 was discovered. Now that it is fixed, we can revert it, so that it sends GOAWAY to grpc clients.

stopctx, cancel := context.WithTimeout(context.Background(), s.cfg.ShutdownTimeout)
defer cancel()
s.httpServer.stop(stopctx)
1pkg marked this conversation as resolved.
Show resolved Hide resolved
return nil
})
if err := g.Wait(); err != http.ErrServerClosed {
Expand Down
Loading