Skip to content

Commit

Permalink
fix attach api ctx error for unknown requests like StoreSafeTS (#720)
Browse files Browse the repository at this point in the history
Signed-off-by: iosmanthus <myosmanthustree@gmail.com>
  • Loading branch information
iosmanthus authored Feb 28, 2023
1 parent 596b794 commit 11d34cb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
5 changes: 1 addition & 4 deletions internal/apicodec/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,7 @@ func attachAPICtx(c Codec, req *tikvrpc.Request) (*tikvrpc.Request, error) {
r.Req = &mpp
}

err := tikvrpc.AttachContext(&r, ctx)
if err != nil {
return nil, err
}
_ = tikvrpc.AttachContext(&r, ctx)

return &r, nil
}
11 changes: 11 additions & 0 deletions internal/apicodec/codec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

"github.com/pingcap/kvproto/pkg/kvrpcpb"
"github.com/stretchr/testify/assert"
"github.com/tikv/client-go/v2/tikvrpc"
)

func TestParseKeyspaceID(t *testing.T) {
Expand Down Expand Up @@ -46,3 +47,13 @@ func TestDecodeKey(t *testing.T) {
assert.Empty(t, pfx)
assert.Empty(t, key)
}

func TestEncodeUnknownRequest(t *testing.T) {
req := &tikvrpc.Request{
Type: tikvrpc.CmdStoreSafeTS,
Req: &kvrpcpb.StoreSafeTSRequest{},
}
c := NewCodecV1(ModeTxn)
_, err := c.EncodeRequest(req)
assert.Nil(t, err)
}

0 comments on commit 11d34cb

Please sign in to comment.