From cbd79c666e077358402c5fd083bd968da43bf15e Mon Sep 17 00:00:00 2001 From: Xiang Li Date: Sat, 23 Apr 2016 21:50:06 -0700 Subject: [PATCH] clientv3: keepaliveonce should have a per call ctx KeepAliveOnce should have a per call ctx. Now we have a per API ctx, but we might do rpc calls mutiple times in a for loop. To avoid unnecessary routine leak, use per call ctx. --- clientv3/lease.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/clientv3/lease.go b/clientv3/lease.go index 1856982fe..1fd03981f 100644 --- a/clientv3/lease.go +++ b/clientv3/lease.go @@ -250,7 +250,10 @@ func (l *lessor) keepAliveCtxCloser(id LeaseID, ctx context.Context, donec <-cha } func (l *lessor) keepAliveOnce(ctx context.Context, id LeaseID) (*LeaseKeepAliveResponse, error) { - stream, err := l.getRemote().LeaseKeepAlive(ctx) + cctx, cancel := context.WithCancel(ctx) + defer cancel() + + stream, err := l.getRemote().LeaseKeepAlive(cctx) if err != nil { return nil, err }