Skip to content

Commit

Permalink
close on canceled (#1121)
Browse files Browse the repository at this point in the history
Signed-off-by: Ping Yu <[email protected]>
  • Loading branch information
pingyu committed Jan 17, 2024
1 parent 605dbe8 commit 9676f18
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
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

0 comments on commit 9676f18

Please sign in to comment.