Skip to content

[grpc] log stack on panic #12724

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
Sep 7, 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
10 changes: 9 additions & 1 deletion components/common-go/grpc/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"crypto/x509"
"os"
"path/filepath"
"runtime/debug"
"time"

"github.com/gitpod-io/gitpod/common-go/log"
Expand All @@ -24,8 +25,10 @@ import (
"golang.org/x/xerrors"
"google.golang.org/grpc"
"google.golang.org/grpc/backoff"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/grpclog"
"google.golang.org/grpc/keepalive"
"google.golang.org/grpc/status"
)

// maxMsgSize use 16MB as the default message size limit.
Expand Down Expand Up @@ -97,7 +100,12 @@ func ServerOptionsWithInterceptors(stream []grpc.StreamServerInterceptor, unary
)
unary = append(unary,
grpc_opentracing.UnaryServerInterceptor(tracingFilterFunc),
grpc_recovery.UnaryServerInterceptor(), // must be last, to be executed first after the rpc handler, we want upstream interceptors to have a meaningful response to work with
grpc_recovery.UnaryServerInterceptor(grpc_recovery.WithRecoveryHandlerContext(
func(ctx context.Context, p interface{}) error {
log.WithField("stack", string(debug.Stack())).Errorf("[PANIC] %s", p)
return status.Errorf(codes.Internal, "%s", p)
},
)), // must be last, to be executed first after the rpc handler, we want upstream interceptors to have a meaningful response to work with
)

return []grpc.ServerOption{
Expand Down