mirror of
https://github.com/restic/rest-server.git
synced 2026-04-12 13:11:50 -07:00
Properly close CPU profile on sigint
The rest server is normally shutdown via a SIGINT signal. The http handle calls are endless loops and don't return in the normal case. Thus add a signal handler to shutdown the profiler.
This commit is contained in:
@@ -6,9 +6,11 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
|
"os/signal"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
"runtime"
|
||||||
"runtime/pprof"
|
"runtime/pprof"
|
||||||
|
"syscall"
|
||||||
|
|
||||||
restserver "github.com/restic/rest-server"
|
restserver "github.com/restic/rest-server"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
@@ -109,7 +111,18 @@ func runRoot(cmd *cobra.Command, args []string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
log.Println("CPU profiling enabled")
|
log.Println("CPU profiling enabled")
|
||||||
defer pprof.StopCPUProfile()
|
|
||||||
|
// clean profiling shutdown on sigint
|
||||||
|
sigintCh := make(chan os.Signal, 1)
|
||||||
|
go func() {
|
||||||
|
for range sigintCh {
|
||||||
|
pprof.StopCPUProfile()
|
||||||
|
f.Close()
|
||||||
|
log.Println("Stopped CPU profiling")
|
||||||
|
os.Exit(130)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
signal.Notify(sigintCh, syscall.SIGINT)
|
||||||
}
|
}
|
||||||
|
|
||||||
handler, err := getHandler(server)
|
handler, err := getHandler(server)
|
||||||
|
|||||||
Reference in New Issue
Block a user