Skip to content

Commit

Permalink
server: add USR1 signal handler to dump goroutine (#7587)
Browse files Browse the repository at this point in the history
  • Loading branch information
lysu authored and coocood committed Sep 3, 2018
1 parent 477de07 commit f270b10
Showing 1 changed file with 16 additions and 6 deletions.
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

0 comments on commit f270b10

Please sign in to comment.