Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

server: add USR1 signal handler to dump goroutine #7587

Merged
merged 10 commits into from
Sep 3, 2018
22 changes: 16 additions & 6 deletions tidb-server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ func main() {
fmt.Println(printer.GetTiDBInfo())
os.Exit(0)
}

registerStores()
loadConfig()
overrideConfig()
Expand Down Expand Up @@ -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.
}
Expand Down