Kevin Wan 3 years ago committed by GitHub
parent fc04ad7854
commit a21ff71373
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -2,6 +2,9 @@ package fx
import ( import (
"context" "context"
"fmt"
"runtime/debug"
"strings"
"time" "time"
) )
@ -30,7 +33,8 @@ func DoWithTimeout(fn func() error, timeout time.Duration, opts ...DoOption) err
go func() { go func() {
defer func() { defer func() {
if p := recover(); p != nil { if p := recover(); p != nil {
panicChan <- p // attach call stack to avoid missing in different goroutine
panicChan <- fmt.Sprintf("%+v\n\n%s", p, strings.TrimSpace(string(debug.Stack())))
} }
}() }()
done <- fn() done <- fn()

@ -39,6 +39,6 @@ func handleCrash(handler func(interface{})) {
} }
func toPanicError(r interface{}) error { func toPanicError(r interface{}) error {
logx.Errorf("%+v %s", r, debug.Stack()) logx.Errorf("%+v\n\n%s", r, debug.Stack())
return status.Errorf(codes.Internal, "panic: %v", r) return status.Errorf(codes.Internal, "panic: %v", r)
} }

@ -2,6 +2,9 @@ package serverinterceptors
import ( import (
"context" "context"
"fmt"
"runtime/debug"
"strings"
"sync" "sync"
"time" "time"
@ -24,7 +27,8 @@ func UnaryTimeoutInterceptor(timeout time.Duration) grpc.UnaryServerInterceptor
go func() { go func() {
defer func() { defer func() {
if p := recover(); p != nil { if p := recover(); p != nil {
panicChan <- p // attach call stack to avoid missing in different goroutine
panicChan <- fmt.Sprintf("%+v\n\n%s", p, strings.TrimSpace(string(debug.Stack())))
} }
}() }()

Loading…
Cancel
Save