Skip to content

Transient Fault Handling #497

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

Merged
merged 16 commits into from
Aug 2, 2017
Merged

Transient Fault Handling #497

merged 16 commits into from
Aug 2, 2017

Conversation

dylan-asos
Copy link
Contributor

This PR implements retry behaviour for transient faults when using HttpClient to send the request.

  • For full backwards compatibility, default behaviour of retry logic is off. Consumer of the library must explicitly enable this using the ReliabilitySettings

  • Retry logic implemented as a delegating handler in the HttpClient handlers pipeline

  • New object ReliabilitySettings defines retry count and retry interval. Setting retry count > 0 enables the behaviour.

  • New object SendGridClientOptions defines the settings to use with SendGridClient, and new ctor allows this object,

public SendGridClient(SendGridClientOptions options)

NB: The overloads were getting quite large and using a options object should allow future changes with no new ctors required. I could've added the reliability settings into one of the ctors, but this way seems cleaner and more future proof.

Testing: The retry logic is tested independently of the main Integration test class in new class RetryDelegatingHandlerTests.cs - just for maintainability and execution time of the unit test, we can test this behaviour independently. Am happy to stick to convention if you'd prefer it all in one file, let me know.

This should be fully backward compatible for all existing consumers - comments welcome, let me know if any issues.

@thinkingserious thinkingserious added the status: code review request requesting a community code review or review from Twilio label Jul 20, 2017
@SendGridDX
Copy link

SendGridDX commented Jul 20, 2017

CLA assistant check
All committers have signed the CLA.

Copy link
Contributor

@thinkingserious thinkingserious left a comment

Choose a reason for hiding this comment

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

First of all, great work!

I just have a few quick changes to start:

  1. Please resolve the merge conflict
  2. Please move this functionalities to the Helpers folder: https://github.com/sendgrid/sendgrid-csharp/tree/master/src/SendGrid/Helpers

Thank you!

@dylan-asos
Copy link
Contributor Author

Sure - who updates the nuspec file? Should that be part of the PR, or do I leave to you?

If me, suggest change to 9.6.1

@thinkingserious
Copy link
Contributor

I will be updating the nuspec file. When I do a minor version bump I start at patch zero. So we would go to 9.6.0. Thanks!

@thinkingserious
Copy link
Contributor

Hi @dylan-asos,

This is just about ready for merge. I have one more ask, could you please add a section here that demonstrates usage?

With Best Regards,

Elmer

@dylan-asos
Copy link
Contributor Author

@thinkingserious
Copy link
Contributor

Perfect, thank you @dylan-asos!

@thinkingserious thinkingserious merged commit bd58fdf into sendgrid:master Aug 2, 2017
@thinkingserious
Copy link
Contributor

Hello @dylan-asos,

Thanks again for the PR!

We want to show our appreciation by sending you some swag. Could you please fill out this form so we can send it to you? Thanks!

Team SendGrid DX

@dylan-asos
Copy link
Contributor Author

You're welcome - we'll be using this package in our project so it helps us out. Hopefully there won't be any, but any bugs or issues raised relating to this just tag me & I'll be happy to look

@dylan-asos
Copy link
Contributor Author

NB: The nuspec file needs the Polly dependency adding. please see the example on my fork,

https://github.com/dylan-asos/sendgrid-csharp/blob/master/nuspec/Sendgrid.9.5.2.nuspec

@thinkingserious
Copy link
Contributor

I'll be fixing this today, @dylan-asos, thanks for making the PR so quickly! There are some concerns about the added complexity of the Polly dependency here. Fixing this issue should be a step in the right direction.

@dylan-asos
Copy link
Contributor Author

Yep I've been following that thread - we certainly can do it without Polly and roll our own. What we need is in the options (RetryCount / Interval), so our own try\catch could achieve the same thing.

Your proposal there sounds good, I'll close the outstanding PR and rework to lose the dependency.

@thinkingserious
Copy link
Contributor

That's awesome @dylan-asos! Thanks for pushing forward on this :D

@Jericho
Copy link

Jericho commented Aug 3, 2017

This PR seems to retry all calls no matter what the error is. Was that the intent?

Did you intend to only retry when SendGrid throws HTTP 429 which indicates that you have reach your rate limit? If that's your intent, you should only retry when appropriate and also try to respect the X-RateLimit-Reset header as documented here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: code review request requesting a community code review or review from Twilio
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants