From a4abd4cbb0552a905b95b5d1e58e95baef9f7a7e Mon Sep 17 00:00:00 2001 From: Haytham Abuelfutuh Date: Mon, 17 May 2021 15:59:26 -0700 Subject: [PATCH] Print stacktrace in interceptPanic (#192) Signed-off-by: Haytham Abuelfutuh --- pkg/rpc/adminservice/base.go | 2 +- pkg/rpc/adminservice/base_test.go | 40 +++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 pkg/rpc/adminservice/base_test.go diff --git a/pkg/rpc/adminservice/base.go b/pkg/rpc/adminservice/base.go index 4f57846ff0..132b8334c8 100644 --- a/pkg/rpc/adminservice/base.go +++ b/pkg/rpc/adminservice/base.go @@ -51,7 +51,7 @@ func (m *AdminService) interceptPanic(ctx context.Context, request proto.Message } m.Metrics.PanicCounter.Inc() - logger.Fatalf(ctx, "panic-ed for request: [%+v] with err: %v", request, err) + logger.Fatalf(ctx, "panic-ed for request: [%+v] with err: %v with Stack: %v", request, err, string(debug.Stack())) } const defaultRetries = 3 diff --git a/pkg/rpc/adminservice/base_test.go b/pkg/rpc/adminservice/base_test.go new file mode 100644 index 0000000000..6e3f1ab4a9 --- /dev/null +++ b/pkg/rpc/adminservice/base_test.go @@ -0,0 +1,40 @@ +package adminservice + +import ( + "context" + "testing" + + "github.com/flyteorg/flytestdlib/logger" + + "github.com/flyteorg/flytestdlib/promutils" + "github.com/golang/protobuf/proto" + "github.com/stretchr/testify/assert" +) + +func Test_interceptPanic(t *testing.T) { + m := AdminService{ + Metrics: InitMetrics(promutils.NewTestScope()), + } + + ctx := context.Background() + + // Mute logs to avoid .Fatal() (called in interceptPanic) causing the process to close + assert.NoError(t, logger.SetConfig(&logger.Config{Mute: true})) + + func() { + defer func() { + if err := recover(); err != nil { + assert.Fail(t, "Unexpected error", err) + } + }() + + a := func() { + defer m.interceptPanic(ctx, proto.Message(nil)) + + var x *int + *x = 10 + } + + a() + }() +}