clientv3: close streams after use in lessor keepAliveOnce method

Streams are now closed after being used in the lessor `keepAliveOnce` method.
This prevents the "failed to receive lease keepalive request from gRPC stream"
message from being logged by the server after the context is cancelled by the
client.

Signed-off-by: Justin Kolberg <amd.prophet@gmail.com>
This commit is contained in:
Justin Kolberg 2022-08-17 12:51:45 -07:00
parent ba0c7c31a7
commit 295044fba2
No known key found for this signature in database
GPG Key ID: 42E9E13080BB3F2B

View File

@ -397,7 +397,7 @@ func (l *lessor) closeRequireLeader() {
}
}
func (l *lessor) keepAliveOnce(ctx context.Context, id LeaseID) (*LeaseKeepAliveResponse, error) {
func (l *lessor) keepAliveOnce(ctx context.Context, id LeaseID) (karesp *LeaseKeepAliveResponse, ferr error) {
cctx, cancel := context.WithCancel(ctx)
defer cancel()
@ -406,6 +406,15 @@ func (l *lessor) keepAliveOnce(ctx context.Context, id LeaseID) (*LeaseKeepAlive
return nil, toErr(ctx, err)
}
defer func() {
if err := stream.CloseSend(); err != nil {
if ferr == nil {
ferr = toErr(ctx, err)
}
return
}
}()
err = stream.Send(&pb.LeaseKeepAliveRequest{ID: int64(id)})
if err != nil {
return nil, toErr(ctx, err)
@ -416,7 +425,7 @@ func (l *lessor) keepAliveOnce(ctx context.Context, id LeaseID) (*LeaseKeepAlive
return nil, toErr(ctx, rerr)
}
karesp := &LeaseKeepAliveResponse{
karesp = &LeaseKeepAliveResponse{
ResponseHeader: resp.GetHeader(),
ID: LeaseID(resp.ID),
TTL: resp.TTL,