Fix goroutine leak in RetryUntilSucceed (#1314)

This commit is contained in:
Jesse Suen 2019-03-22 11:50:00 -07:00 committed by GitHub
parent e482d74d19
commit 1f675f4bb9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -85,10 +85,13 @@ func MakeSignature(size int) ([]byte, error) {
// RetryUntilSucceed keep retrying given action with specified timeout until action succeed or specified context is done.
func RetryUntilSucceed(action func() error, desc string, ctx context.Context, timeout time.Duration) {
ctxCompleted := false
stop := make(chan bool)
defer close(stop)
go func() {
select {
case <-ctx.Done():
ctxCompleted = true
case <-stop:
}
}()
for {