Skip to content

Commit

Permalink
Merge pull request #237 from xmidt-org/panic-fix
Browse files Browse the repository at this point in the history
Patch: WRP Decoder Panic
  • Loading branch information
maurafortino authored Feb 17, 2023
2 parents f18ae77 + 1c0122e commit 64845d3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [Unreleased]
- [ Scytale: WRP Decoder Panic #236] (https://github.com/xmidt-org/scytale/issues/236)

## [v0.7.2]
- Remove several unused build files and update the docker images to work. [179](https://github.com/xmidt-org/scytale/pull/209)
Expand Down
15 changes: 11 additions & 4 deletions primaryHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,6 @@ func NewPrimaryHandler(logger log.Logger, v *viper.Viper, registry xmetrics.Regi
var (
// nolint:govet,bodyclose
transactor = fanout.NewTransactor(cfg)
decoder = wrphttp.DefaultDecoder()
options = []fanout.Option{
fanout.WithTransactor(transactor),
fanout.WithErrorEncoder(func(ctx context.Context, err error, w http.ResponseWriter) {
Expand Down Expand Up @@ -422,12 +421,20 @@ func NewPrimaryHandler(logger log.Logger, v *viper.Viper, registry xmetrics.Regi
append(
options,
fanout.WithFanoutBefore(
func(ctx context.Context, _, fanout *http.Request, body []byte) (context.Context, error) {
entity, err := decoder(ctx, fanout)
func(ctx context.Context, original, fanout *http.Request, body []byte) (context.Context, error) {
var m wrp.Message

f, err := wrphttp.DetermineFormat(wrp.Msgpack, original.Header, "Content-Type")
if err != nil {
return nil, err
}
return context.WithValue(ctx, ContextKeyWRP, entity.Message), nil

err = wrp.NewDecoderBytes(body, f).Decode(&m)
if err != nil {
return nil, err
}

return context.WithValue(ctx, ContextKeyWRP, m), nil
},
fanout.ForwardHeaders("Content-Type", "X-Webpa-Device-Name"),
fanout.UsePath(fmt.Sprintf("%s/device/send", fanoutPrefix)),
Expand Down

0 comments on commit 64845d3

Please sign in to comment.