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

ResourceExhausted error code to HTTP 429 status code #270

Merged
merged 2 commits into from
Sep 16, 2020

Conversation

marioizquierdo
Copy link
Contributor

@marioizquierdo marioizquierdo commented Sep 14, 2020

Followup after PR: #258

After all the analysis done in #258, we decided to re-map ResourceExhausted to 429 Too Many Requests, instead of adding a new status code. See PR comments for more details.

Backwards compatibility

This is a non-backwards compatible change, although it may only affect servers and their middleware; clients are not affected by the HTTP status code. Note that, since the update happens on the twirp package, the update takes effect when the package is updated.

Backwards compatibility notes about changing the HTTP mapping code of resource_exhausted from 403 to 429:

  • ✅ : New clients can handle all codes from old services (HTTP codes are not used to deserialize errors).
  • ⚠️ : Old clients in Go handle 429 errors from intermediaries (non-twirp services or middleware) as unavailable (see code). New clients will handle them as resource_exhausted.
  • ⚠️ : Old clients in different languages may have different ways to handle errors from intermediaries. We should file an issue on other implementations to warn them of the update.
  • ⚠️ : Old clients receiving errors from new services will still map resource_exhausted as 403, even if in the server it is mapped to 429 (the mapping is done in code).
  • ❌ : Middleware and proxies that depend on HTTP codes need to be reviewed and updated to handle 429. This update is not easy, and in some cases may be impossible (maybe the middleware is managed by a different team). During the update, the middleware needs to handle both 429 and 403 during codes properly.
  • ❌ : Monitoring based on HTTP codes needs to be reviewed.

(✅ = it just works, ⚠️ = corner cases may need attention, ❌ = code depending on previous behavior needs to be updated)

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@marioizquierdo marioizquierdo changed the title Map ResourceExhausted error code to HTTP 429 status code ResourceExhausted error code to HTTP 429 status code Sep 14, 2020
docs/spec_v7.md Outdated
@@ -208,7 +208,7 @@ corresponding HTTP Status Code for the response.
| already_exists | 409 | An attempt to create an entity failed because one already exists.
| permission_denied | 403 | The caller does not have permission to execute the specified operation. It must not be used if the caller cannot be identified (use "unauthenticated" instead).
| unauthenticated | 401 | The request does not have valid authentication credentials for the operation.
| resource_exhausted | 403 | Some resource has been exhausted, perhaps a per-user quota, or perhaps the entire file system is out of space.
| resource_exhausted | 429 | Some resource has been exhausted, perhaps a per-user quota, or perhaps the entire file system is out of space.
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it worth mentioning rate-limiting here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What about adding "exhausted or rate-limited"?

Some resource has been exhausted or rate-limited, perhaps a per-user quota, or perhaps the entire file system is out of space

t.P(` case 429, 502, 503, 504: // Too Many Requests, Bad Gateway, Service Unavailable, Gateway Timeout`)
t.P(` case 429: // Too Many Requests`)
t.P(` code = `, t.pkgs["twirp"], `.ResourceExhausted`)
t.P(` case 502, 503, 504: // Too Many Requests, Bad Gateway, Service Unavailable, Gateway Timeout`)
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove "Too Many Requests" from this line

@marioizquierdo marioizquierdo merged commit 3865fde into master Sep 16, 2020
@marioizquierdo marioizquierdo deleted the resource_exhausted_429 branch September 16, 2020 07:30
sagikazarmark added a commit to twirphp/twirp that referenced this pull request Nov 1, 2021
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.

2 participants