diff --git a/tidb-server/main.go b/tidb-server/main.go index 57b0941338983..3d3e8ab2f6090 100644 --- a/tidb-server/main.go +++ b/tidb-server/main.go @@ -128,7 +128,6 @@ func main() { fmt.Println(printer.GetTiDBInfo()) os.Exit(0) } - registerStores() loadConfig() overrideConfig() @@ -433,20 +432,31 @@ func createServer() { } func setupSignalHandler() { - sc := make(chan os.Signal, 1) - signal.Notify(sc, + usrDefSignalChan := make(chan os.Signal, 1) + signal.Notify(usrDefSignalChan, syscall.SIGUSR1) + go func() { + buf := make([]byte, 1<<16) + for { + sig := <-usrDefSignalChan + if sig == syscall.SIGUSR1 { + stackLen := runtime.Stack(buf, true) + log.Printf("\n=== Got signal [%s] to dump goroutine stack. ===\n%s\n=== Finished dumping goroutine stack. ===\n", sig, buf[:stackLen]) + } + } + }() + + closeSignalChan := make(chan os.Signal, 1) + signal.Notify(closeSignalChan, syscall.SIGHUP, syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT) - go func() { - sig := <-sc + sig := <-closeSignalChan log.Infof("Got signal [%s] to exit.", sig) if sig == syscall.SIGQUIT { graceful = true } - if xsvr != nil { xsvr.Close() // Should close xserver before server. }