Skip to content

Commit

Permalink
do not cancel admin api
Browse files Browse the repository at this point in the history
  • Loading branch information
svenwltr committed Jun 15, 2022
1 parent 2150395 commit 093f872
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
7 changes: 3 additions & 4 deletions examples/full/cmd/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,9 @@ func (s *Server) Run(ctx context.Context) error {
// running routines and should used once on program startup.
group, ctx := errgroup.WithContext(ctx)

// Set up the admin API and defer the function that it returns. The admin
// API lifecycle differs from the context, so it actually is the last thing
// that gets shut down.
defer webutil.AdminAPIListenAndServe(ctx)()
// Set up the admin API. The admin API lifecycle differs from the context,
// so it actually is the last thing that gets shut down.
webutil.AdminAPIListenAndServe(ctx)

// Other background processes.
s.setupHTTPServer(ctx, group)
Expand Down
9 changes: 4 additions & 5 deletions pkg/webutil/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/rebuy-de/rebuy-go-sdk/v4/pkg/logutil"
)

func AdminAPIListenAndServe(ctx context.Context, healthy ...func() error) func() {
func AdminAPIListenAndServe(ctx context.Context, healthy ...func() error) {
ctx = logutil.Start(ctx, "admin-api")
mux := http.NewServeMux()

Expand Down Expand Up @@ -46,8 +46,9 @@ func AdminAPIListenAndServe(ctx context.Context, healthy ...func() error) func()
// The admin api gets a its own context, because we want to delay the
// server shutdown as long as possible. The reason for this is that Istio
// starts to block all outgoing connections as soon as there is no
// listening server anymore.
bg, cancel := context.WithCancel(context.Background())
// listening server anymore. Also a graceful shutdown is not needed for the
// admin API, so it is also not necessary to cancel the context.
bg := context.Background()

go func() {
logutil.Get(ctx).Debugf("admin api listening on port 8090")
Expand All @@ -57,6 +58,4 @@ func AdminAPIListenAndServe(ctx context.Context, healthy ...func() error) func()
logutil.Get(ctx).Error(err.Error())
}
}()

return cancel
}

0 comments on commit 093f872

Please sign in to comment.