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

Retry after certain Cloudflare errors #991

Merged
merged 3 commits into from Dec 14, 2019

Conversation

dguo
Copy link
Contributor

@dguo dguo commented Dec 13, 2019

Checklist

Many of the Cloudflare error codes seem appropriate for retry.

I omitted the SSL ones with the reasoning that those are unlikely to be intermittent. I also omitted 530 because it can refer to many errors, like hitting a rate limit.

  • I have read the documentation.
  • I have included a pull request description of my changes.
  • I have included some tests.
  • If it's a new feature, I have included documentation updates.

readme.md Outdated
@@ -367,7 +367,7 @@ Default:
- limit: `2`
- calculateDelay: `(attemptCount, retryOptions, error, computedValue) => computedValue`
- methods: `GET` `PUT` `HEAD` `DELETE` `OPTIONS` `TRACE`
- statusCodes: [`408`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/408) [`413`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/413) [`429`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/429) [`500`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/500) [`502`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/502) [`503`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/503) [`504`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/504)
- statusCodes: [`408`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/408) [`413`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/413) [`429`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/429) [`500`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/500) [`502`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/502) [`503`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/503) [`504`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/504) [`520`](https://support.cloudflare.com/hc/en-us/articles/115003011431#520error) [`521`](https://support.cloudflare.com/hc/en-us/articles/115003011431#521error) [`522`](https://support.cloudflare.com/hc/en-us/articles/115003011431#522error) [`523`](https://support.cloudflare.com/hc/en-us/articles/115003011431#523error) [`524`](https://support.cloudflare.com/hc/en-us/articles/115003011431#524error) [`527`](https://support.cloudflare.com/hc/en-us/articles/115003011431#527error)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Only 522 and 524 should be retry-able.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Other 5XX codes are not.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just so I understand why, is your reasoning that the other ones are unlikely to be intermittent?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm glad you've asked 😃 Got retries on timeouts by default, so 522 and 524 are OK.

On the other hand, 520 is caused by a server error which is not likely to disappear:

image

521 is web server is down, it makes no sense to retry.

523 is origin is unreachable - CloudFlare cannot find a route to the server, it makes no sense to retry either.

527 is Railgun Listener to origin error and it has these common causes:

image

It isn't safe to retry on 527 as we don't know if the request timed out or not.

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 explanation. I made the change.

Copy link
Collaborator

Choose a reason for hiding this comment

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

We retry on ECONNREFUSED and ECONNRESET though, so 521 is appriopriate here: https://community.cloudflare.com/t/community-tip-fixing-error-521-web-server-is-down/42461

Let me finish this for you :)

@szmarczak
Copy link
Collaborator

Don't forget to include some tests :)

@dguo
Copy link
Contributor Author

dguo commented Dec 14, 2019

I didn't add a test because I figured a test would sort of mirror the code (e.g. effectively asserting that the array of status codes is what it is in the code).

Would you like me to add a test anyway? What do you think would be a useful one? I could add one that loops through the array and makes sure all of those status codes generate a retry.

@szmarczak
Copy link
Collaborator

I didn't add a test because I figured a test would sort of mirror the code (e.g. effectively asserting that the array of status codes is what it is in the code).

Ah, you're right. I don't think more tests are necessary at this point.

@szmarczak
Copy link
Collaborator

Good job! 🙌

@szmarczak szmarczak merged commit 0569d45 into sindresorhus:master Dec 14, 2019
@dguo dguo deleted the retry-cloudflare-errors branch December 14, 2019 17:55
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.

None yet

2 participants