Skip to content

send SIGUSR1 to dump all goroutines (for debugging) #1860

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

Merged
merged 1 commit into from
Jan 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions cmd/server/main-server.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"github.com/wavetermdev/waveterm/pkg/service"
"github.com/wavetermdev/waveterm/pkg/telemetry"
"github.com/wavetermdev/waveterm/pkg/util/shellutil"
"github.com/wavetermdev/waveterm/pkg/util/utilfn"
"github.com/wavetermdev/waveterm/pkg/wavebase"
"github.com/wavetermdev/waveterm/pkg/waveobj"
"github.com/wavetermdev/waveterm/pkg/wcloud"
Expand Down Expand Up @@ -75,13 +76,29 @@
sigCh := make(chan os.Signal, 1)
signal.Notify(sigCh, syscall.SIGHUP, syscall.SIGTERM, syscall.SIGINT)
go func() {
defer func() {
panichandler.PanicHandler("installShutdownSignalHandlers", recover())
}()
for sig := range sigCh {
doShutdown(fmt.Sprintf("got signal %v", sig))
break
}
}()
}

func installSIGUSR1Handler() {
sigCh := make(chan os.Signal, 1)
signal.Notify(sigCh, syscall.SIGUSR1)

Check failure on line 91 in cmd/server/main-server.go

View workflow job for this annotation

GitHub Actions / Build for TestDriver.ai

undefined: syscall.SIGUSR1
go func() {
defer func() {
panichandler.PanicHandler("installSIGUSR1Handler", recover())
}()
for range sigCh {
utilfn.DumpGoRoutineStacks()
}
}()
}

// watch stdin, kill server if stdin is closed
func stdinReadWatch() {
buf := make([]byte, 1024)
Expand Down Expand Up @@ -296,6 +313,7 @@

createMainWshClient()
installShutdownSignalHandlers()
installSIGUSR1Handler()
startupActivityUpdate()
go stdinReadWatch()
go telemetryLoop()
Expand Down
7 changes: 7 additions & 0 deletions pkg/util/utilfn/utilfn.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"os/exec"
"reflect"
"regexp"
"runtime"
"sort"
"strconv"
"strings"
Expand Down Expand Up @@ -941,3 +942,9 @@ func HasBinaryData(data []byte) bool {
}
return false
}

func DumpGoRoutineStacks() {
buf := make([]byte, 1<<20)
n := runtime.Stack(buf, true)
os.Stdout.Write(buf[:n])
}
Loading