Skip to content

Commit

Permalink
add more timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
CharlesCheung96 committed Mar 11, 2022
1 parent b04d170 commit cec8e43
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions pkg/etcd/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,10 @@ func (c *Client) Txn(ctx context.Context, cmps []clientv3.Cmp, opsThen, opsElse
// Grant delegates request to clientv3.Lease.Grant
func (c *Client) Grant(ctx context.Context, ttl int64) (resp *clientv3.LeaseGrantResponse, err error) {
err = retryRPC(EtcdGrant, c.metrics[EtcdGrant], func() error {
grantCtx, cancel := context.WithTimeout(ctx, etcdClientTimeoutWithoutRetry)
defer cancel()
var inErr error
resp, inErr = c.cli.Grant(ctx, ttl)
resp, inErr = c.cli.Grant(grantCtx, ttl)
return inErr
})
return
Expand Down Expand Up @@ -190,8 +192,10 @@ func isRetryableError(rpcName string) retry.IsRetryable {
// Revoke delegates request to clientv3.Lease.Revoke
func (c *Client) Revoke(ctx context.Context, id clientv3.LeaseID) (resp *clientv3.LeaseRevokeResponse, err error) {
err = retryRPC(EtcdRevoke, c.metrics[EtcdRevoke], func() error {
revokeCtx, cancel := context.WithTimeout(ctx, etcdClientTimeoutWithoutRetry)
defer cancel()
var inErr error
resp, inErr = c.cli.Revoke(ctx, id)
resp, inErr = c.cli.Revoke(revokeCtx, id)
return inErr
})
return
Expand All @@ -200,8 +204,10 @@ func (c *Client) Revoke(ctx context.Context, id clientv3.LeaseID) (resp *clientv
// TimeToLive delegates request to clientv3.Lease.TimeToLive
func (c *Client) TimeToLive(ctx context.Context, lease clientv3.LeaseID, opts ...clientv3.LeaseOption) (resp *clientv3.LeaseTimeToLiveResponse, err error) {
err = retryRPC(EtcdRevoke, c.metrics[EtcdRevoke], func() error {
timeToLiveCtx, cancel := context.WithTimeout(ctx, etcdClientTimeoutWithoutRetry)
defer cancel()
var inErr error
resp, inErr = c.cli.TimeToLive(ctx, lease, opts...)
resp, inErr = c.cli.TimeToLive(timeToLiveCtx, lease, opts...)
return inErr
})
return
Expand Down

0 comments on commit cec8e43

Please sign in to comment.