webapi: Refine server start/stop logging.

Don't log errors returned by server.Shutdown. They are exceedingly
unlikely, and there is nothing which can be done about them.

Moving the "Listening on..." log closer to where the server is actually
started reduces the chance of confusion. Also, logging the parsed
listener.Addr() string instead of the provided config string provides
extra debugging detail.
This commit is contained in:
jholdstock 2023-09-16 08:05:58 +01:00 committed by Jamie Holdstock
parent ee4a440534
commit 72b0411ee0

View File

@ -120,7 +120,6 @@ func New(vdb *database.VspDatabase, log slog.Logger, dcrd rpc.DcrdConnect,
if err != nil { if err != nil {
return nil, err return nil, err
} }
log.Infof("Listening on %s", cfg.Listen)
w := &WebAPI{ w := &WebAPI{
cfg: cfg, cfg: cfg,
@ -152,17 +151,16 @@ func (w *WebAPI) Run(ctx context.Context) {
<-ctx.Done() <-ctx.Done()
w.log.Debug("Stopping webserver...") w.log.Debug("Stopping webserver...")
if err := w.server.Shutdown(ctx); err != nil { _ = w.server.Shutdown(ctx)
w.log.Errorf("Failed to stop webserver cleanly: %v", err) w.log.Debug("Webserver stopped")
} else {
w.log.Debug("Webserver stopped")
}
wg.Done() wg.Done()
}() }()
// Start webserver. // Start webserver.
wg.Add(1) wg.Add(1)
go func() { go func() {
w.log.Infof("Listening on %s", w.listener.Addr())
err := w.server.Serve(w.listener) err := w.server.Serve(w.listener)
// ErrServerClosed is expected from a graceful server shutdown, it can // ErrServerClosed is expected from a graceful server shutdown, it can
// be ignored. Anything else should be logged. // be ignored. Anything else should be logged.