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
API client: don't retry on POST #7383
Conversation
@@ -4,13 +4,12 @@ | |||
|
|||
import requests | |||
from django.conf import settings | |||
from requests.packages.urllib3.util.retry import Retry # noqa |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
requests was just importing this from urlib3 https://github.com/psf/requests/blob/master/requests/packages.py
@@ -41,7 +40,7 @@ def setup_api(): | |||
connect=3, | |||
status=3, | |||
backoff_factor=0.5, # 0.5, 1, 2 seconds | |||
method_whitelist=('GET', 'PUT', 'PATCH', 'POST'), | |||
method_whitelist=('GET', 'PUT', 'PATCH'), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This defaults to https://urllib3.readthedocs.io/en/latest/reference/urllib3.util.html#urllib3.util.retry.Retry.DEFAULT_METHOD_WHITELIST seem like nice defaults, except I'd add patch too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do think we want to retry POST on some status codes, if there is support for it. For example, a 502 we likely don't want to retry, but I think we do on a 503. I think this is better than nothing if we can't customize that, but it would be great to have more control.
It seems status_forcelist
is likely what we want, and to continue to include POST in this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
RETRY_AFTER_STATUS_CODES
maybe is actually what we want.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, I omitted the 504 response (Gateway Timeout). Not sure about 502 Bad Gateway
https://en.wikipedia.org/wiki/List_of_HTTP_status_codes#5xx_Server_errors
But anyway, when it times out with post, it doesn't return any status code (it times out bc it hasn't responded yet!). So using that won't prevent from triggering the task multiple times.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point re: timeout.
POST isn't idempotent and can trigger some expensive operations several times (like sync_versions).
b2f288f
to
7b5d41c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will be curious to see how this changes our sentry error rates.
@@ -41,7 +40,7 @@ def setup_api(): | |||
connect=3, | |||
status=3, | |||
backoff_factor=0.5, # 0.5, 1, 2 seconds | |||
method_whitelist=('GET', 'PUT', 'PATCH', 'POST'), | |||
method_whitelist=('GET', 'PUT', 'PATCH'), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point re: timeout.
POST isn't idempotent and can trigger some expensive operations
several times (like sync_versions).