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

Stats endpoint API should shut down cleanly #107

Open
fearful-symmetry opened this issue Mar 8, 2023 · 2 comments
Open

Stats endpoint API should shut down cleanly #107

fearful-symmetry opened this issue Mar 8, 2023 · 2 comments
Labels
Team:Elastic-Agent Label for the Agent team Team:Elastic-Agent-Control-Plane Label for the Agent Control Plane team

Comments

@fearful-symmetry
Copy link
Contributor

cc @cmacknz
In cases where agent is shut down cleanly (for example, with a sigint), we get this message:

{"log.level":"info","@timestamp":"2023-03-08T10:47:12.737-0800","log.logger":"api","log.origin":{"file.name":"api/server.go","file.line":72},"message":"Stats endpoint (127.0.0.1:6791) finished: accept tcp 127.0.0.1:6791: use of closed network connection","log":{"source":"elastic-agent"},"ecs.version":"1.6.0"}

This is a benign error, but it's almost always the last message we get when agent shuts down, which means users might get confused and assume it's somehow related to the shutdown. We should either clarify the error message to make it sound less threatening, or change the (s *Server) Stop() method so we don't print an error during "normal" shutdown.

@fearful-symmetry fearful-symmetry added the Team:Elastic-Agent Label for the Agent team label Mar 8, 2023
@cmacknz cmacknz transferred this issue from elastic/elastic-agent-libs Mar 8, 2023
@cmacknz cmacknz transferred this issue from elastic/elastic-agent Mar 8, 2023
@cmacknz
Copy link
Member

cmacknz commented Mar 8, 2023

// Start starts the HTTP server and accepting new connection.
func (s *Server) Start() {
s.log.Info("Starting stats endpoint")
go func(l net.Listener) {
s.log.Infof("Metrics endpoint listening on: %s (configured: %s)", l.Addr().String(), s.config.Host)
err := http.Serve(l, s.mux)
s.log.Infof("Stats endpoint (%s) finished: %v", l.Addr().String(), err)
}(s.l)
}
// Stop stops the API server and free any resource associated with the process like unix sockets.
func (s *Server) Stop() error {
return s.l.Close()
}

Seems be because we pass a net.Listener to the default http.Server, instead of creating a server and calling close on the server, which would let us check for ErrServerClosed and not log it.

// Serve accepts incoming HTTP connections on the listener l,
// creating a new service goroutine for each. The service goroutines
// read requests and then call handler to reply to them.
//
// The handler is typically nil, in which case the DefaultServeMux is used.
//
// HTTP/2 support is only enabled if the Listener returns *tls.Conn
// connections and they were configured with "h2" in the TLS
// Config.NextProtos.
//
// Serve always returns a non-nil error.
func Serve(l net.Listener, handler Handler) error {
	srv := &Server{Handler: handler}
	return srv.Serve(l)
}

@michel-laterman
Copy link
Contributor

fyi i added #168 to expose shutdown to the caller

@ycombinator ycombinator added the Team:Elastic-Agent-Control-Plane Label for the Agent Control Plane team label May 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Team:Elastic-Agent Label for the Agent team Team:Elastic-Agent-Control-Plane Label for the Agent Control Plane team
Projects
None yet
Development

No branches or pull requests

4 participants