|
|
@@ -15,6 +15,7 @@
|
|
|
package clientv3
|
|
|
|
|
|
import (
|
|
|
+ "errors"
|
|
|
"sync"
|
|
|
"time"
|
|
|
|
|
|
@@ -69,6 +70,8 @@ const (
|
|
|
NoLease LeaseID = 0
|
|
|
)
|
|
|
|
|
|
+var ErrLeaseHalted = errors.New("etcdclient: leases halted")
|
|
|
+
|
|
|
type Lease interface {
|
|
|
// Grant creates a new lease.
|
|
|
Grant(ctx context.Context, ttl int64) (*LeaseGrantResponse, error)
|
|
|
@@ -216,6 +219,14 @@ func (l *lessor) KeepAlive(ctx context.Context, id LeaseID) (<-chan *LeaseKeepAl
|
|
|
ch := make(chan *LeaseKeepAliveResponse, leaseResponseChSize)
|
|
|
|
|
|
l.mu.Lock()
|
|
|
+ // ensure that recvKeepAliveLoop is still running
|
|
|
+ select {
|
|
|
+ case <-l.donec:
|
|
|
+ l.mu.Unlock()
|
|
|
+ close(ch)
|
|
|
+ return ch, ErrLeaseHalted
|
|
|
+ default:
|
|
|
+ }
|
|
|
ka, ok := l.keepAlives[id]
|
|
|
if !ok {
|
|
|
// create fresh keep alive
|