Skip to content

Commit

Permalink
webapi: Refine server start/stop logging.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jholdstock committed Sep 16, 2023
1 parent ee4a440 commit 72b0411
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions internal/webapi/webapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ func New(vdb *database.VspDatabase, log slog.Logger, dcrd rpc.DcrdConnect,
if err != nil {
return nil, err
}
log.Infof("Listening on %s", cfg.Listen)

w := &WebAPI{
cfg: cfg,
Expand Down Expand Up @@ -152,17 +151,16 @@ func (w *WebAPI) Run(ctx context.Context) {
<-ctx.Done()

w.log.Debug("Stopping webserver...")
if err := w.server.Shutdown(ctx); err != nil {
w.log.Errorf("Failed to stop webserver cleanly: %v", err)
} else {
w.log.Debug("Webserver stopped")
}
_ = w.server.Shutdown(ctx)
w.log.Debug("Webserver stopped")

wg.Done()
}()

// Start webserver.
wg.Add(1)
go func() {
w.log.Infof("Listening on %s", w.listener.Addr())
err := w.server.Serve(w.listener)
// ErrServerClosed is expected from a graceful server shutdown, it can
// be ignored. Anything else should be logged.
Expand Down

0 comments on commit 72b0411

Please sign in to comment.