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

fix(requests): got calls will be retried on response code 429 #361 #728

Conversation

JonasSchubert
Copy link
Contributor

@JonasSchubert JonasSchubert commented Jun 1, 2024

If got receives a response code 429 - too many requests - it will retry up to three times.
This utilizes the retry API https://github.com/sindresorhus/got/blob/main/documentation/7-retry.md
I am open to change the amount of retries as I selected three as a - for me - good first choice (third time's a charm 😄)

@JonasSchubert JonasSchubert force-pushed the feat/use-got-retry-if-too-many-requests-error-is-returned-#361 branch from aaf1091 to e8ff582 Compare June 2, 2024 08:59
…c-release#361

If got receives a response code 429 - too many requests - it will retry up to three times for GET and POST requests.
This uses the retry API https://github.com/sindresorhus/got/blob/main/documentation/7-retry.md
@JonasSchubert JonasSchubert force-pushed the feat/use-got-retry-if-too-many-requests-error-is-returned-#361 branch from 3a0ec19 to 333a8ea Compare June 2, 2024 09:16
@JonasSchubert
Copy link
Contributor Author

Might also help to fix #529


export const RETRY_CONFIGURATION = {
retry: {
limit: 3,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Default in got is 2. I am open for discussion.

@@ -1,3 +1,10 @@
export const HOME_URL = 'https://github.com/semantic-release/semantic-release';

export const RELEASE_NAME = 'GitLab release';

export const RETRY_CONFIGURATION = {
retry: {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We could try to calculate the retryAfter property into optimizing the calculation for the next try.

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes indeed. I assumed we are overriding the retry options when setting the apiOptions. I was wrong. Thanks for properly looking into it. I will close this PR.
What is still confusing though are the reported 429 responses of some users...

@@ -567,7 +567,7 @@ test.serial("Throw error if GitLab API return any other errors", async (t) => {
const owner = "test_user";
const repo = "test_repo";
const env = { GITLAB_TOKEN: "gitlab_token" };
const gitlab = authenticate(env).get(`/projects/${owner}%2F${repo}`).times(3).reply(500);
const gitlab = authenticate(env).get(`/projects/${owner}%2F${repo}`).times(3).reply(500).persist();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

.persist is needed to avoid confusing nock errors.

Copy link
Contributor

@fgreinacher fgreinacher Jun 5, 2024

Choose a reason for hiding this comment

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

See comment above

export const RETRY_CONFIGURATION = {
retry: {
limit: 3,
statusCodes: [429],
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we can go with the default here:

Suggested change
statusCodes: [429],

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will close this PR. Thanks for reviewing!

@fgreinacher
Copy link
Contributor

fgreinacher commented Jun 5, 2024

Thanks for the PR @JonasSchubert!

I was not aware that got retries failed requests by default, see https://github.com/sindresorhus/got/blob/cc346b79561b13e3a266b22b7f612fca5a45eb1e/documentation/quick-start.md#retries.

Have you specifically noticed issues with the default configuration (2 retries, more status codes)?

Copy link
Contributor Author

@JonasSchubert JonasSchubert left a comment

Choose a reason for hiding this comment

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

I will close this PR as got is using a default setup for the retries (retrying twice). Wondering now, why some users report 429 if got is covering this already.

@@ -1,3 +1,10 @@
export const HOME_URL = 'https://github.com/semantic-release/semantic-release';

export const RELEASE_NAME = 'GitLab release';

export const RETRY_CONFIGURATION = {
retry: {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes indeed. I assumed we are overriding the retry options when setting the apiOptions. I was wrong. Thanks for properly looking into it. I will close this PR.
What is still confusing though are the reported 429 responses of some users...

export const RETRY_CONFIGURATION = {
retry: {
limit: 3,
statusCodes: [429],
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will close this PR. Thanks for reviewing!

test/publish.test.js Show resolved Hide resolved
@fgreinacher
Copy link
Contributor

I will close this PR as got is using a default setup for the retries (retrying twice). Wondering now, why some users report 429 if got is covering this already.

We still raise the error after retrying after 2 retries, and also https://github.com/sindresorhus/got/blob/main/documentation/7-retry.md#maxretryafter might be relevant here.

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

Successfully merging this pull request may close these issues.

2 participants