From 39d9d22ca3d20d9b76d7f767ac846eb995e1669b Mon Sep 17 00:00:00 2001 From: Jeffrey Morgan Date: Mon, 6 May 2024 16:01:37 -0700 Subject: [PATCH] close server on receiving signal (#4213) --- cmd/cmd.go | 7 ++++++- server/routes.go | 1 + 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/cmd/cmd.go b/cmd/cmd.go index faac424c..bf305d81 100644 --- a/cmd/cmd.go +++ b/cmd/cmd.go @@ -898,7 +898,12 @@ func RunServer(cmd *cobra.Command, _ []string) error { return err } - return server.Serve(ln) + err = server.Serve(ln) + if errors.Is(err, http.ErrServerClosed) { + return nil + } + + return err } func initializeKeypair() error { diff --git a/server/routes.go b/server/routes.go index e878598a..da51fbbe 100644 --- a/server/routes.go +++ b/server/routes.go @@ -1041,6 +1041,7 @@ func Serve(ln net.Listener) error { signal.Notify(signals, syscall.SIGINT, syscall.SIGTERM) go func() { <-signals + srvr.Close() done() sched.unloadAllRunners() gpu.Cleanup()