diff --git a/cmd/skaffold/app/cmd/commands.go b/cmd/skaffold/app/cmd/commands.go index 482225dcf73..f1c4564405c 100644 --- a/cmd/skaffold/app/cmd/commands.go +++ b/cmd/skaffold/app/cmd/commands.go @@ -89,7 +89,8 @@ func (b *builder) ExactArgs(argCount int, action func(context.Context, io.Writer b.cmd.Args = cobra.ExactArgs(argCount) b.cmd.RunE = func(_ *cobra.Command, args []string) error { err := handleWellKnownErrors(action(b.cmd.Context(), b.cmd.OutOrStdout(), args)) - // clean up server. + // clean up server at end of the execution since post run hooks are only executed if + // RunE is successful if shutdownAPIServer != nil { shutdownAPIServer() } @@ -102,6 +103,8 @@ func (b *builder) NoArgs(action func(context.Context, io.Writer) error) *cobra.C b.cmd.Args = cobra.NoArgs b.cmd.RunE = func(*cobra.Command, []string) error { err := handleWellKnownErrors(action(b.cmd.Context(), b.cmd.OutOrStdout())) + // clean up server at end of the execution since post run hooks are only executed if + // RunE is successful if shutdownAPIServer != nil { shutdownAPIServer() } diff --git a/pkg/skaffold/server/server.go b/pkg/skaffold/server/server.go index dfe269e7909..4640d721408 100644 --- a/pkg/skaffold/server/server.go +++ b/pkg/skaffold/server/server.go @@ -38,8 +38,8 @@ import ( var ( srv *server - // waits for 1 second before shutting down the server - secondTimeout = 1 * time.Second + // waits for 1 second before forcing a server shutdown + forceShutdownTimeout = 1 * time.Second ) type server struct { @@ -161,7 +161,7 @@ func newGRPCServer(port int) (func() error, error) { } }() return func() error { - ctx, cancel := context.WithTimeout(context.Background(), secondTimeout) + ctx, cancel := context.WithTimeout(context.Background(), forceShutdownTimeout) defer cancel() ch := make(chan bool, 1) go func() { @@ -194,14 +194,13 @@ func newHTTPServer(port, proxyPort int) (func() error, error) { logrus.Infof("starting gRPC HTTP server on port %d", port) server := &http.Server{ - Handler: mux, - ReadTimeout: 10 * time.Second, + Handler: mux, } - go http.Serve(l, mux) + go server.Serve(l) return func() error { - ctx, cancel := context.WithTimeout(context.Background(), secondTimeout) + ctx, cancel := context.WithTimeout(context.Background(), forceShutdownTimeout) defer cancel() return server.Shutdown(ctx) }, nil