-
Notifications
You must be signed in to change notification settings - Fork 140
CBG-4714: collect goroutine stack traces on signal #7870
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
base: main
Are you sure you want to change the base?
Changes from 9 commits
ce80821
1beaae4
df92f51
033a788
2e41703
0ec5e51
ac7795c
201310a
8207199
e54a721
2c1bfeb
027cd4f
085e411
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| # Copyright 2025-Present Couchbase, Inc. | ||
| # | ||
| # Use of this software is governed by the Business Source License included | ||
| # in the file licenses/BSL-Couchbase.txt. As of the Change Date specified | ||
| # in that file, in accordance with the Business Source License, use of this | ||
| # software will be governed by the Apache License, Version 2.0, included in | ||
| # the file licenses/APL2.txt. | ||
| get: | ||
| summary: Get stack trace for all goroutines | ||
| description: |- | ||
| Returns stack traces of all running goroutines in Sync Gateway. | ||
|
|
||
| Required Sync Gateway RBAC roles: | ||
|
|
||
| * Sync Gateway Dev Ops | ||
| responses: | ||
| '200': | ||
| description: OK | ||
| content: | ||
| application/json: | ||
| schema: | ||
| type: string | ||
| tags: | ||
| - Profiling | ||
| operationId: get__debug-stacktrace |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| //go:build !windows | ||
gregns1 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| // +build !windows | ||
|
|
||
| /* | ||
| Copyright 2025-Present Couchbase, Inc. | ||
| Use of this software is governed by the Business Source License included in | ||
| the file licenses/BSL-Couchbase.txt. As of the Change Date specified in that | ||
| file, in accordance with the Business Source License, use of this software will | ||
| be governed by the Apache License, Version 2.0, included in the file | ||
| licenses/APL2.txt. | ||
| */ | ||
|
|
||
| package rest | ||
|
|
||
| import ( | ||
| "context" | ||
| "os" | ||
| "os/signal" | ||
| "syscall" | ||
| "time" | ||
|
|
||
| "github.com/couchbase/sync_gateway/base" | ||
| ) | ||
|
|
||
| // registerSignalHandlerForStackTrace will register a signal handler to capture stack traces | ||
gregns1 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| // - SIGUSR1 causes Sync Gateway to record a stack trace of all running goroutines. | ||
| func (sc *ServerContext) registerSignalHandlerForStackTrace(ctx context.Context) { | ||
| signalChannel := make(chan os.Signal, 1) | ||
| signal.Notify(signalChannel, syscall.SIGUSR1) | ||
|
|
||
| defer func() { | ||
| signal.Stop(signalChannel) | ||
| close(signalChannel) | ||
| }() | ||
|
|
||
| go func() { | ||
| select { | ||
| case sig := <-signalChannel: | ||
| base.InfofCtx(ctx, base.KeyAll, "Handling signal: %v", sig) | ||
| switch sig { | ||
| case syscall.SIGUSR1: | ||
| // stack trace signal received | ||
| currentTime := time.Now() | ||
| timestamp := currentTime.Format(time.RFC3339) | ||
| sc.logStackTraces(ctx, timestamp) | ||
|
||
| default: | ||
| // unhandled signal here | ||
| } | ||
| case <-ctx.Done(): | ||
| return | ||
| } | ||
| }() | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| //go:build windows | ||
| // +build windows | ||
|
|
||
| /* | ||
| Copyright 2025-Present Couchbase, Inc. | ||
|
|
||
| Use of this software is governed by the Business Source License included in | ||
| the file licenses/BSL-Couchbase.txt. As of the Change Date specified in that | ||
| file, in accordance with the Business Source License, use of this software will | ||
| be governed by the Apache License, Version 2.0, included in the file | ||
| licenses/APL2.txt. | ||
| */ | ||
|
|
||
| package rest | ||
|
|
||
| // registerSignalHandlerForStackTrace will register a signal handler to capture stack traces | ||
| // - SIGUSR1 causes Sync Gateway to record a stack trace of all running goroutines. | ||
| func (sc *ServerContext) registerSignalHandlerForStackTrace(ctx context.Context) { | ||
|
Check failure on line 18 in rest/stack_trace_handler_windows.go
|
||
| // No-op on Windows | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.