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

client: prevent keyspace client from panic #7899

Merged
merged 1 commit into from
Mar 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
"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 @@
Header: c.requestHeader(),
Name: name,
}
resp, err := c.keyspaceClient().LoadKeyspace(ctx, req)
protoClient := c.keyspaceClient()
if protoClient == nil {
cancel()
return nil, errs.ErrClientGetProtoClient

Check warning on line 63 in client/keyspace_client.go

View check run for this annotation

Codecov / codecov/patch

client/keyspace_client.go#L62-L63

Added lines #L62 - L63 were not covered by tests
}
resp, err := protoClient.LoadKeyspace(ctx, req)
cancel()

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

Check warning on line 108 in client/keyspace_client.go

View check run for this annotation

Codecov / codecov/patch

client/keyspace_client.go#L107-L108

Added lines #L107 - L108 were not covered by tests
}
resp, err := protoClient.UpdateKeyspaceState(ctx, req)
cancel()

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

Check warning on line 152 in client/keyspace_client.go

View check run for this annotation

Codecov / codecov/patch

client/keyspace_client.go#L151-L152

Added lines #L151 - L152 were not covered by tests
}
resp, err := protoClient.GetAllKeyspaces(ctx, req)
cancel()

if err != nil {
Expand Down
Loading