Skip to content

retry http 5xx status as well #139

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 1 commit into from
Jan 6, 2019
Merged

retry http 5xx status as well #139

merged 1 commit into from
Jan 6, 2019

Conversation

dbu
Copy link
Contributor

@dbu dbu commented Dec 29, 2018

Q A
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? yes
Related tickets fixes #126
Documentation php-http/documentation#246
License MIT

What's in this PR?

Add retry for responses with a server error status code.

Checklist

  • Updated CHANGELOG.md to describe BC breaks / deprecations | new feature | bugfix

TODO

@dbu dbu force-pushed the retry-server-errors branch from a78400d to 39d992d Compare December 29, 2018 09:37
@dbu dbu added this to the v2.0.0 milestone Dec 29, 2018
Copy link
Member

@Nyholm Nyholm left a comment

Choose a reason for hiding this comment

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

Good, I like this

@dbu
Copy link
Contributor Author

dbu commented Dec 30, 2018

i'll backport the rename to 1.9 with deprecation, and remove the BC code here

@dbu
Copy link
Contributor Author

dbu commented Dec 30, 2018

rebased and cleaned up. this is now ready for review again.

Copy link
Member

@Nyholm Nyholm left a comment

Choose a reason for hiding this comment

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

Good, just some minor changes

@dbu dbu force-pushed the retry-server-errors branch from 8bfb2f8 to 29ff637 Compare January 2, 2019 07:37
@dbu dbu force-pushed the retry-server-errors branch 2 times, most recently from 8164de2 to 4dfc148 Compare January 2, 2019 08:32
@dbu dbu changed the title no exception should be thrown on server error, but retrying those wou… retry http 5xx status as well Jan 2, 2019
@dbu dbu force-pushed the retry-server-errors branch 3 times, most recently from 9c86096 to 0d8afd7 Compare January 2, 2019 09:30
@dbu dbu force-pushed the retry-server-errors branch from 0d8afd7 to 5be99a5 Compare January 2, 2019 16:29
@sagikazarmark
Copy link
Member

Are you sure this is a good idea? 5xx generally means everything is broken and the server tells the client to leave them alone. Imagine if everyone retried requests upon an 500 error: poor server wouldn't have any chance to recover.

@Nyholm
Copy link
Member

Nyholm commented Jan 2, 2019

What other request should you retry? 4xx means that the request itself is wrong.

@sagikazarmark
Copy link
Member

Not necessarily. 404 could mean a resource is not ready yet, but will be at some point.

I guess retry from application and retry from http client point of view mean two different things.

@GrahamCampbell
Copy link
Contributor

Not necessarily. 404 could mean a resource is not ready yet, but will be at some point.

People can always configure reties themselves for that case though. For example, I do this when hitting the GitHub API, because they have a lag due to SQL replication.

@dbu
Copy link
Contributor Author

dbu commented Jan 3, 2019

to me retrying 5xx seems reasonable, might be a temporary lapse in server communication or a database deadlock or whatnot.

we can also by default not retry any response codes, if we think that is better. just having the configuration option has value already. what do we do?

@dbu dbu force-pushed the retry-server-errors branch from 5be99a5 to 4a1a919 Compare January 3, 2019 07:33
@Nyholm
Copy link
Member

Nyholm commented Jan 3, 2019

If you are using the RetryPlugin you are assuming that at least some request should be retried.

I understand both arguments. I guess it depends on what kind of services you are using. I dont mind retrying my 500 requests when Im requesting github. But I may reconsider if I querying my own "easy to dos"-servers.

I vote for a merge.

@dbu
Copy link
Contributor Author

dbu commented Jan 3, 2019

But I may reconsider if I querying my own "easy to dos"-servers.

we can add a warning in the documentation. there is the exponential backoff, so there is not that much requests to be expected.

@dbu dbu changed the base branch from 2.x to master January 3, 2019 13:54
@dbu dbu force-pushed the retry-server-errors branch from 4a1a919 to dd8cfcd Compare January 3, 2019 13:56
@dbu dbu force-pushed the retry-server-errors branch 2 times, most recently from 91978ed to 71c7aa9 Compare January 3, 2019 16:36
@dbu
Copy link
Contributor Author

dbu commented Jan 3, 2019

added documentation PR and realized i only want to retry codes from 500 to < 600. some systems (ab)use higher http status codes for custom things and we don't want to accidentally interact with those by default.

@dbu dbu force-pushed the retry-server-errors branch from 71c7aa9 to 2810181 Compare January 4, 2019 09:33
@Nyholm Nyholm requested a review from sagikazarmark January 4, 2019 10:42
Copy link
Contributor

@GrahamCampbell GrahamCampbell left a comment

Choose a reason for hiding this comment

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

Looks good. 👍

Copy link
Member

@sagikazarmark sagikazarmark 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 @dbu

@sagikazarmark sagikazarmark merged commit 9da616d into master Jan 6, 2019
@sagikazarmark sagikazarmark deleted the retry-server-errors branch January 6, 2019 06:18
@gmponos
Copy link
Contributor

gmponos commented Jan 6, 2019

  1. On this PR you are altering the default behavior of the plugin but a developer can set his own if he wishes to right? For what it is worth as a consumer developer I would never use this plugin without setting my custom callback functions... Therefore I would prefer if the default is null.
  2. For the reason above I would prefer if the callback were allowed to be also null instead of having to pass a callback function with just a return...
  3. For me this line return !$e instanceof HttpException || $e->getCode() >= 500 && $e->getCode() < 600; is confusing... It might make sense in the cases where you have a PluginClient with the ErrorPlugin inside of it... if the PluginClient becomes a PSR compatible client then according to PSR

A Client MUST NOT treat a well-formed HTTP request or HTTP response as an error condition. For example, response status codes in the 400 and 500 range MUST NOT cause an exception and MUST be returned to the Calling Library as normal.

So I don't understand how this $e->getCode() >= 500 && $e->getCode() < 600 can be fullfilled.. Because it is confusing I would really love if someone has the time to represent a full example with this. Maybe on a test...

On another topic please rethink the usage of ErrorPlugin with PluginClient on v2. On a discussion we had on chat if we initialize on v2 a PluginClient with the ErrorPlugin it wont be compatible with PSR-18

@gmponos
Copy link
Contributor

gmponos commented Jan 6, 2019

For what it is worth as a consumer developer I would never use this plugin without setting my custom callback functions..

Elaborating this.. Using guzzle retry middleware... I only tend to retry 503 cases and also cases that the request was not even sent.. (status code 0 because of cURL)... Or cases that I got a response and I must look inside of the response...

@dbu
Copy link
Contributor Author

dbu commented Jan 6, 2019

allowing to pass null makes the code more complicated. and the plugin is not active by default, so it can be used if wanted but is not needed. the exception part of the plugin indeed only makes sense with the error plugin - this is also explicitly mentioned in the documentation to avoid confusion

following our slack discussion, i added a note to the ErrorPlugin that indeed it is violating PSR-18. it can still be used when writing an application and wanting exceptions, but must not be used with third party libraries.

@gmponos
Copy link
Contributor

gmponos commented Jan 6, 2019

allowing to pass null makes the code more complicated.

and the plugin is not active by default

I understand these part.. None the less the null has to be taken in consideration along with the other parts that I said...

I saw also the documentation.. but I don't believe that the documentation here saves the day.. in overall, for what my opinion is worth it, I am not excited very much about these changes... :)

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.

Retry Plugin should also retry responses with status 5xx
5 participants