-
Notifications
You must be signed in to change notification settings - Fork 5.9k
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
Conversation
/run-all-tests |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
tidb-server/main.go
Outdated
select { | ||
case sig := <-sc: | ||
if sig == syscall.SIGUSR1 { | ||
buf := make([]byte, 1<<20) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This may cause a deadlock.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
make([]byte, 1<<20)
??
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure about it, see golang/go#23360, for more details.
tidb-server/main.go
Outdated
buf := make([]byte, 1<<16) | ||
for { | ||
sig := <-dumpSignalChan | ||
if sig == syscall.SIGUSR1 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't need to check the signal.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe future we need other signal?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this if and sig local variable is in purpose
tidb-server/main.go
Outdated
if sig == syscall.SIGUSR1 { | ||
stackLen := runtime.Stack(buf, true) | ||
log.Printf("=== Got signal [%s] to goroutine dump===\n*** goroutine dump...\n%s\n*** end\n", sig, buf[:stackLen]) | ||
continue |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
continue
can be removed
tidb-server/main.go
Outdated
@@ -48,7 +48,7 @@ import ( | |||
"github.com/pingcap/tidb/util/printer" | |||
"github.com/pingcap/tidb/util/systimemon" | |||
"github.com/pingcap/tidb/x-server" | |||
binlog "github.com/pingcap/tipb/go-binlog" | |||
"github.com/pingcap/tipb/go-binlog" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This useless alias is used for some contributors to read the code easily. You could check its commit log.
Btw, I want to remove it either.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.....I didn't modify it...it seem IDE or make fmt change it 🤣 I will rollback it.
LGTM |
@coocood manual test seems be pass too |
tidb-server/main.go
Outdated
sig := <-dumpSignalChan | ||
if sig == syscall.SIGUSR1 { | ||
stackLen := runtime.Stack(buf, true) | ||
log.Printf("=== Got signal [%s] to goroutine dump===\n*** goroutine dump...\n%s\n*** end\n", sig, buf[:stackLen]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how about:
=== Got signal [%s] to dump goroutine stack. ===
%s
=== Finished dumping goroutine stack. ===
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done~~
What problem does this PR solve?
relate to #7558, we add USR1 signal handler to dump goroutine stack into stdout.
What is changed and how it works?
Check List
Tests
pkill -USR1 tidb-server
to send signal and check stdout seeSleep(time.Mintue*20) in cleanup(main.go).
pkill -QUIT tidb-server
to shutdown tidb-serverpkill -USR1 tidb-server
again and got dump output tooCode changes
Side effects
Related changes
This change is