webapi: Use existing context for server shutdown.
The server will shutdown cleanly even if the passed context is already canceled, so there is no need to pass a new context and blindly guess at how long the server may need to stop.
This commit is contained in:
parent
f881179024
commit
61b6460014
@ -148,14 +148,11 @@ func (w *WebAPI) Run(ctx context.Context) {
|
||||
// Add the graceful shutdown to the waitgroup.
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
// Wait until shutdown is signaled before shutting down.
|
||||
// Wait until context is canceled before shutting down the server.
|
||||
<-ctx.Done()
|
||||
|
||||
w.log.Debug("Stopping webserver...")
|
||||
// Give the webserver 10 seconds to finish what it is doing.
|
||||
timeoutCtx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||
defer cancel()
|
||||
if err := w.server.Shutdown(timeoutCtx); err != nil {
|
||||
if err := w.server.Shutdown(ctx); err != nil {
|
||||
w.log.Errorf("Failed to stop webserver cleanly: %v", err)
|
||||
} else {
|
||||
w.log.Debug("Webserver stopped")
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user