Skip to content

Commit

Permalink
client: prevent keyspace client from panic (#7899)
Browse files Browse the repository at this point in the history
ref #7902

Signed-off-by: Ryan Leung <[email protected]>
  • Loading branch information
rleungx authored Mar 8, 2024
1 parent 46c8a6f commit 1d77b25
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions client/keyspace_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"github.com/opentracing/opentracing-go"
"github.com/pingcap/errors"
"github.com/pingcap/kvproto/pkg/keyspacepb"
"github.com/tikv/pd/client/errs"
)

// KeyspaceClient manages keyspace metadata.
Expand Down Expand Up @@ -56,7 +57,12 @@ func (c *client) LoadKeyspace(ctx context.Context, name string) (*keyspacepb.Key
Header: c.requestHeader(),
Name: name,
}
resp, err := c.keyspaceClient().LoadKeyspace(ctx, req)
protoClient := c.keyspaceClient()
if protoClient == nil {
cancel()
return nil, errs.ErrClientGetProtoClient
}
resp, err := protoClient.LoadKeyspace(ctx, req)
cancel()

if err != nil {
Expand Down Expand Up @@ -96,7 +102,12 @@ func (c *client) UpdateKeyspaceState(ctx context.Context, id uint32, state keysp
Id: id,
State: state,
}
resp, err := c.keyspaceClient().UpdateKeyspaceState(ctx, req)
protoClient := c.keyspaceClient()
if protoClient == nil {
cancel()
return nil, errs.ErrClientGetProtoClient
}
resp, err := protoClient.UpdateKeyspaceState(ctx, req)
cancel()

if err != nil {
Expand Down Expand Up @@ -135,7 +146,12 @@ func (c *client) GetAllKeyspaces(ctx context.Context, startID uint32, limit uint
StartId: startID,
Limit: limit,
}
resp, err := c.keyspaceClient().GetAllKeyspaces(ctx, req)
protoClient := c.keyspaceClient()
if protoClient == nil {
cancel()
return nil, errs.ErrClientGetProtoClient
}
resp, err := protoClient.GetAllKeyspaces(ctx, req)
cancel()

if err != nil {
Expand Down

0 comments on commit 1d77b25

Please sign in to comment.