mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
clientv3: return error from KeepAlive if corresponding loop exits
after recvKeepAliveLoop exits client might call KeepAlive adding request channel that will not be closed this fix makes sure that recvKeepAliveLoop is running before adding request to lessor's list and returns error otherwise Fixes #6922
This commit is contained in:
parent
a9f72ee0d4
commit
e0bcd4d516
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user