Skip to content

Commit

Permalink
Merge pull request #49 from ExpediaGroup/tipike/odfv_bugs
Browse files Browse the repository at this point in the history
improve panic handling for python transformation
  • Loading branch information
piket authored Oct 4, 2023
2 parents d361307 + 042bed6 commit 5e7d144
Showing 1 changed file with 26 additions and 4 deletions.
30 changes: 26 additions & 4 deletions go/internal/feast/transformation/transformation.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package transformation
import (
"errors"
"fmt"
"runtime"
"strings"
"unsafe"

Expand Down Expand Up @@ -129,14 +130,23 @@ func CallTransformations(

// Recover from a panic from FFI so the server doesn't crash
var err error
ret := callback(featureView.Base.Name, inputArrPtr, inputSchemaPtr, outArrPtr, outSchemaPtr, fullFeatureNames)
defer func() {
if e := recover(); e != nil {
ret = -1
log.Error().Err(err).Msg("")
err = fmt.Errorf("python transformation callback error: %v", e)
logStackTrace()
switch value := e.(type) {
case error:
log.Error().Err(value).Msg("")
err = fmt.Errorf("python transformation callback error: %w\n", value)
case string:
log.Error().Msg(value)
err = fmt.Errorf("python transformation callback error: %s\n", value)
default:
log.Error().Msg("Unknown panic")
err = fmt.Errorf("python transformation callback error: %v\n", value)
}
}
}()
ret := callback(featureView.Base.Name, inputArrPtr, inputSchemaPtr, outArrPtr, outSchemaPtr, fullFeatureNames)

if ret != numRows {
return nil, errors.New("python transformation callback failed")
Expand Down Expand Up @@ -223,3 +233,15 @@ func getNeededRequestData(requestedOnDemandFeatureViews []*model.OnDemandFeature

return neededRequestData, nil
}

func logStackTrace() {
// Create a buffer for storing the stack trace
const size = 4096
buf := make([]byte, size)

// Retrieve the stack trace and write it to the buffer
stackSize := runtime.Stack(buf, false)

// Log the stack trace using zerolog
log.Error().Str("stack_trace", string(buf[:stackSize])).Msg("")
}

0 comments on commit 5e7d144

Please sign in to comment.