浏览代码

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.
Xiang Li 9 年之前
父节点
当前提交
cbd79c666e
共有 1 个文件被更改,包括 4 次插入1 次删除
  1. 4 1
      clientv3/lease.go

+ 4 - 1
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) {
 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 {
 	if err != nil {
 		return nil, err
 		return nil, err
 	}
 	}