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

Close connection when get gRPC error Code.Canceled #1121

Merged
merged 1 commit into from
Jan 17, 2024
Merged
Show file tree
Hide file tree
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
4 changes: 3 additions & 1 deletion internal/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,9 @@ func (a *connArray) monitoredDial(ctx context.Context, connName, target string,

func (c *monitoredConn) Close() error {
if c.ClientConn != nil {
return c.ClientConn.Close()
err := c.ClientConn.Close()
logutil.BgLogger().Debug("close gRPC connection", zap.String("target", c.Name), zap.Error(err))
return err
}
return nil
}
Expand Down
10 changes: 6 additions & 4 deletions internal/locate/region_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -1832,10 +1832,12 @@ func (s *RegionRequestSender) onSendFail(bo *retry.Backoffer, ctx *RPCContext, r
case <-bo.GetCtx().Done():
return errors.WithStack(err)
default:
// If we don't cancel, but the error code is Canceled, it must be from grpc remote.
// This may happen when tikv is killed and exiting.
// Backoff and retry in this case.
logutil.Logger(bo.GetCtx()).Warn("receive a grpc cancel signal from remote", zap.Error(err))
// If we don't cancel, but the error code is Canceled, it may be canceled by keepalive or gRPC remote.
// For the case of canceled by keepalive, we need to re-establish the connection, otherwise following requests will always fail.
// Canceled by gRPC remote may happen when tikv is killed and exiting.
// Close the connection, backoff, and retry.
logutil.Logger(bo.GetCtx()).Warn("receive a grpc cancel signal", zap.Error(err))
s.client.CloseAddr(ctx.Addr)
}
}

Expand Down
Loading