Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix history client NPE for invalid shardID #2679

Merged
merged 1 commit into from
Mar 30, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
46 changes: 19 additions & 27 deletions client/history/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,15 +186,13 @@ func (c *clientImpl) DescribeHistoryHost(
func (c *clientImpl) RemoveTask(
ctx context.Context,
request *historyservice.RemoveTaskRequest,
opts ...grpc.CallOption) (*historyservice.RemoveTaskResponse, error) {
var err error
var client historyservice.HistoryServiceClient
if request.GetShardId() != 0 {
client, err = c.getClientForShardID(request.GetShardId())
if err != nil {
return nil, err
}
opts ...grpc.CallOption,
) (*historyservice.RemoveTaskResponse, error) {
client, err := c.getClientForShardID(request.GetShardId())
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getClientForShardID will check if shardID <= 0 and return an invalid argument error.

if err != nil {
return nil, err
}

var response *historyservice.RemoveTaskResponse
op := func(ctx context.Context, client historyservice.HistoryServiceClient) error {
var err error
Expand All @@ -214,16 +212,13 @@ func (c *clientImpl) RemoveTask(
func (c *clientImpl) CloseShard(
ctx context.Context,
request *historyservice.CloseShardRequest,
opts ...grpc.CallOption) (*historyservice.CloseShardResponse, error) {

var err error
var client historyservice.HistoryServiceClient
if request.ShardId != 0 {
client, err = c.getClientForShardID(request.GetShardId())
if err != nil {
return nil, err
}
opts ...grpc.CallOption,
) (*historyservice.CloseShardResponse, error) {
client, err := c.getClientForShardID(request.GetShardId())
if err != nil {
return nil, err
}

var response *historyservice.CloseShardResponse
op := func(ctx context.Context, client historyservice.HistoryServiceClient) error {
var err error
Expand All @@ -243,16 +238,13 @@ func (c *clientImpl) CloseShard(
func (c *clientImpl) GetShard(
ctx context.Context,
request *historyservice.GetShardRequest,
opts ...grpc.CallOption) (*historyservice.GetShardResponse, error) {

var err error
var client historyservice.HistoryServiceClient
if request.ShardId != 0 {
client, err = c.getClientForShardID(request.GetShardId())
if err != nil {
return nil, err
}
opts ...grpc.CallOption,
) (*historyservice.GetShardResponse, error) {
client, err := c.getClientForShardID(request.GetShardId())
if err != nil {
return nil, err
}

var response *historyservice.GetShardResponse
op := func(ctx context.Context, client historyservice.HistoryServiceClient) error {
var err error
Expand Down Expand Up @@ -830,7 +822,7 @@ func (c *clientImpl) SyncShardStatus(
opts ...grpc.CallOption) (*historyservice.SyncShardStatusResponse, error) {

// we do not have a workflow ID here, instead, we have something even better
client, err := c.getClientForShardID(int32(request.GetShardId()))
client, err := c.getClientForShardID(request.GetShardId())
if err != nil {
return nil, err
}
Expand Down