Skip to content

Commit

Permalink
clientv3: return on RPC(context deadline or cancelled) error
Browse files Browse the repository at this point in the history
  • Loading branch information
xiang90 committed Feb 2, 2016
1 parent 0ef001a commit 3a7a3ee
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions clientv3/lease.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ func (l *lessor) Close() error {

l.stopCancel()
l.stream = nil

return nil
}

Expand Down Expand Up @@ -213,11 +214,25 @@ func (l *lessor) recvKeepAliveLoop() {
return
}

defer func() {
l.mu.Lock()
defer l.mu.Unlock()

for _, ch := range l.keepAlives {
close(ch)
}
}()

for {
stream := l.getKeepAliveStream()

resp, err := stream.Recv()
if err != nil {
if isRPCError(err) {
l.Close()
return
}

err := l.switchRemoteAndStream(err)
if err != nil {
l.Close()
Expand Down Expand Up @@ -279,7 +294,12 @@ func (l *lessor) sendKeepAliveLoop() {
for _, id := range tosend {
r := &pb.LeaseKeepAliveRequest{ID: int64(id)}
err := stream.Send(r)

if err != nil {
if isRPCError(err) {
l.Close()
return
}
break
}
}
Expand Down

0 comments on commit 3a7a3ee

Please sign in to comment.