Fix panic caused by ETCD client timeout on Revoke() #409
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When revoking a lease, for example on app shutdown, there is a scenario on which ETCD client takes more than
revokeTimeout
to respond.In this scenario, the timed action would trigger a
defer close(c)
and close the channel, but wouldnt cancel the Revoke operation. Therefore, as thesd.cli.Revoke(ctx, sd.leaseID)
returns and then tries to write the result on the channel, panic is triggered:The suggested approach to handle timeouts with ETCD client is to set the timeout into the context.
Note that this same issue could happen on
renewLease()
ifgrantLeaseTimeout
is ever smaller thanetcdDialTimeout
. The default configuration is safe, so I am not changing this one.