Skip to content

Commit

Permalink
Print stacktrace in interceptPanic (flyteorg#192)
Browse files Browse the repository at this point in the history
Signed-off-by: Haytham Abuelfutuh <[email protected]>
  • Loading branch information
EngHabu authored May 17, 2021
1 parent a0544da commit c5e4c86
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
2 changes: 1 addition & 1 deletion flyteadmin/pkg/rpc/adminservice/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
40 changes: 40 additions & 0 deletions flyteadmin/pkg/rpc/adminservice/base_test.go
Original file line number Diff line number Diff line change
@@ -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()
}()
}

0 comments on commit c5e4c86

Please sign in to comment.