Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

client/v3: Add backoff before retry when watch stream returns unavailable #14556

Merged
merged 1 commit into from
Oct 12, 2022

Conversation

tomari
Copy link
Contributor

@tomari tomari commented Oct 7, 2022

The client retries connection without backoff when the server is gone after the watch stream is established. This results in high CPU usage in the client process. This change introduces backoff when the stream is failed and unavailable.

Signed-off-by: Hisanobu Tomari [email protected]

}
}
time.Sleep(backoff)
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code is duplicated to

etcd/client/v3/watch.go

Lines 1018 to 1028 in 6a0bbf3

if isUnavailableErr(w.ctx, err) {
// retry, but backoff
if backoff < maxBackoff {
// 25% backoff factor
backoff = backoff + backoff/4
if backoff > maxBackoff {
backoff = maxBackoff
}
}
time.Sleep(backoff)
}

Please get it included in a function so that it can be reused by both places.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the review. The backoff function has been added.

…able

The client retries connection without backoff when the server is gone
after the watch stream is established. This results in high CPU usage
in the client process. This change introduces backoff when the stream is
failed and unavailable.

Signed-off-by: Hisanobu Tomari <[email protected]>
Copy link
Member

@ahrtr ahrtr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Thank you @tomari

@codecov-commenter
Copy link

Codecov Report

Merging #14556 (6a0bbf3) into main (6a0bbf3) will not change coverage.
The diff coverage is n/a.

❗ Current head 6a0bbf3 differs from pull request most recent head 428fb96. Consider uploading reports for the commit 428fb96 to get more accurate results

@@           Coverage Diff           @@
##             main   #14556   +/-   ##
=======================================
  Coverage   75.46%   75.46%           
=======================================
  Files         457      457           
  Lines       37187    37187           
=======================================
  Hits        28064    28064           
  Misses       7373     7373           
  Partials     1750     1750           
Flag Coverage Δ
all 75.46% <0.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

Copy link
Member

@spzala spzala left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm. Thanks @tomari

@ahrtr
Copy link
Member

ahrtr commented Oct 12, 2022

@tomari Could you backport the fix to 3.5 and 3.4?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

4 participants