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

API client: don't retry on POST #7383

Merged
merged 2 commits into from Aug 26, 2020
Merged

API client: don't retry on POST #7383

merged 2 commits into from Aug 26, 2020

Conversation

stsewd
Copy link
Member

@stsewd stsewd commented Aug 12, 2020

POST isn't idempotent and can trigger some expensive operations
several times (like sync_versions).

@@ -4,13 +4,12 @@

import requests
from django.conf import settings
from requests.packages.urllib3.util.retry import Retry # noqa
Copy link
Member Author

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'),
Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Member

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.

Copy link
Member

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.

Copy link
Member Author

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.

Copy link
Member

Choose a reason for hiding this comment

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

Good point re: timeout.

@stsewd stsewd requested a review from a team August 12, 2020 23:06
POST isn't idempotent and can trigger some expensive operations
several times (like sync_versions).
Copy link
Member

@ericholscher ericholscher left a 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'),
Copy link
Member

Choose a reason for hiding this comment

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

Good point re: timeout.

@stsewd stsewd merged commit d93c5eb into master Aug 26, 2020
@stsewd stsewd deleted the dont-retry-post branch August 26, 2020 18:15
stsewd added a commit that referenced this pull request Sep 3, 2020
stsewd added a commit that referenced this pull request Sep 3, 2020
agjohnson pushed a commit that referenced this pull request Sep 3, 2020
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