Skip to content
Merged
Changes from all 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
12 changes: 12 additions & 0 deletions cmd/gateway/serve.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package gateway

import (
"context"
_ "embed"
"errors"
"fmt"
Expand Down Expand Up @@ -292,6 +293,17 @@ var serveCmd = &cobra.Command{
e.GET("/routing/v1/peers/*", routingHandler)
}

// shut down the server gracefully on context cancellation
go func() {
<-cmd.Context().Done()
cmd.Println("\nShutting down server...")
ctx, cancel := context.WithTimeout(cmd.Context(), time.Second*5)
defer cancel()
if err := e.Shutdown(ctx); err != nil {
cmd.PrintErrf("shutting down server: %s", err.Error())
}
}()

// print banner after short delay to ensure it only appears if no errors
// occurred during startup
timer := time.NewTimer(time.Second)
Expand Down
Loading