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

log panic full stack #7410

Merged
merged 2 commits into from
Oct 13, 2022
Merged
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
11 changes: 11 additions & 0 deletions pkg/storage/stores/shipper/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package util

import (
"fmt"
"os"
"runtime"
"runtime/debug"
"unsafe"

Expand All @@ -11,6 +13,7 @@ import (
"github.com/grafana/loki/pkg/storage/stores/series/index"
)

const maxStackSize = 8 * 1024
const sep = "\xff"

func BuildIndexFileName(tableName, uploader, dbName string) string {
Expand Down Expand Up @@ -48,6 +51,7 @@ func safeOpenBoltDbFile(path string, ret chan *result) {

defer func() {
if r := recover(); r != nil {
logPanic(r)
res.err = fmt.Errorf("recovered from panic opening boltdb file: %v", r)
}

Expand Down Expand Up @@ -85,3 +89,10 @@ func GetUnsafeBytes(s string) []byte {
func GetUnsafeString(buf []byte) string {
return *((*string)(unsafe.Pointer(&buf)))
}

func logPanic(p interface{}) {
stack := make([]byte, maxStackSize)
stack = stack[:runtime.Stack(stack, true)]
// keep a multiline stack
fmt.Fprintf(os.Stderr, "panic: %v\n%s", p, stack)
}