| 736 | } |
| 737 | |
| 738 | func stopAdminServer(srv *http.Server) error { |
| 739 | if srv == nil { |
| 740 | return fmt.Errorf("no admin server") |
| 741 | } |
| 742 | timeout := 10 * time.Second |
| 743 | ctx, cancel := context.WithTimeoutCause(context.Background(), timeout, fmt.Errorf("stopping admin server: %ds timeout", int(timeout.Seconds()))) |
| 744 | defer cancel() |
| 745 | err := srv.Shutdown(ctx) |
| 746 | if err != nil { |
| 747 | if cause := context.Cause(ctx); cause != nil && errors.Is(err, context.DeadlineExceeded) { |
| 748 | err = cause |
| 749 | } |
| 750 | return fmt.Errorf("shutting down admin server: %v", err) |
| 751 | } |
| 752 | Log().Named("admin").Info("stopped previous server", zap.String("address", srv.Addr)) |
| 753 | return nil |
| 754 | } |
| 755 | |
| 756 | // AdminRouter is a type which can return routes for the admin API. |
| 757 | type AdminRouter interface { |