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

Automatic request retries #1518

Merged
merged 1 commit into from
Feb 16, 2019
Merged

Automatic request retries #1518

merged 1 commit into from
Feb 16, 2019

Conversation

ob-stripe
Copy link
Contributor

r? @brandur-stripe @remi-stripe
cc @stripe/api-libraries

Add support for automatic request retries.

The implementation is based on stripe-go, so the retry conditions are the same: requests are retried on connection errors (timeouts) and 409's. Given the recent discussions in e.g. stripe/stripe-node#559, let me know if you want me to change the conditions (e.g. to retry on 500's).

Copy link
Contributor

@brandur-stripe brandur-stripe left a comment

Choose a reason for hiding this comment

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

One comment below, but looks great!

ptal @ob-stripe

return true;
}

if (statusCode == HttpStatusCode.Conflict)
Copy link
Contributor

Choose a reason for hiding this comment

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

It might be worth adding 503s here and non-POST 500s as recently came into stripe-node. I think that's the direction we're going, and we just haven't changed stripe-go yet.

@ob-stripe
Copy link
Contributor Author

I've updated ShouldRetry to also retry on 503's and non-POST 5xx's, similar to stripe-node.

I also realized there were a few important bits missing, which I also updated:

  • we now set an idempotency key for all POST requests, if one is not already provided by the user (it would have been pretty dangerous to ship automatic retries without this!)
  • non-timeout connection errors are reported as HttpRequestExceptions. These are now handled like timeout errors.
  • I've also improved error handling to be a bit more resilient with unexpected bodies (I was getting NullPointerExceptions in some of my tests because I was returning {} as the body and the error handling code tries to access the error key in the JSON hash)

ptal @brandur-stripe

@brandur-stripe
Copy link
Contributor

  • we now set an idempotency key for all POST requests, if one is not already provided by the user (it would have been pretty dangerous to ship automatic retries without this!)

Phew! Glad you caught that one before shipping, haha.

LGTM!

@ob-stripe ob-stripe merged commit 8069bd3 into integration-v23 Feb 16, 2019
@ob-stripe ob-stripe deleted the ob-auto-retries branch February 16, 2019 00:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants