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

Exponential backoff if Sentry server returns 429 #839

Merged
merged 6 commits into from
Jan 27, 2017
Merged

Conversation

benvinegar
Copy link
Contributor

@benvinegar
Copy link
Contributor Author

Should there be a max duration, e.g. 2 minutes or something?


_send: function(data) {
if (this._shouldBackoff()) {
return;
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd suggest that we console.log or something that this is happening. That way we're not dropping things in the dark without any insight as to why if someone were to debug. Including ourselves.

@mattrobenolt
Copy link
Contributor

imo we can do similar, if not the same behavior for a few different status codes. Not just 429.

We have cases of someone revoking a DSN, in which case SDKs will continue to spam the old key. Or the project is deleted entirely, with code still out in production continuing to spam. In theory, we could be more aggressive about these errors and just 100% shut down the SDK, but that might just be more complexity in code base.

  • 400 status would be if the project_id didn't exist or some other fatal error. This would be safe to abort entirely or back off. This is not recoverable without re-configuring the client to fix the problem.
  • 401 status is for unauthorized, and this is when the project id would match, but the DSN is invalid. So either the credentials are flat out wrong, or they have been revoked. This would be safe to abort entirely or back off. This is not recoverable without re-configuring the client to fix the problem.
  • 403 status is overloaded for a couple reasons, one of them being Event dropped due to filter, so we wouldn't want to change behavior for this.
  • 429, obvious. That's why we're here. But one thing worth noting, in lots of cases, we spit back a Retry-After header that would be applicable to use as a backoff time, if it's easy to read this. The response will say Retry-After: 10 to say, "chill for 10 seconds". If you can read this, it'd be preferable over backing off since this is an accurate time for when the rate limit is going to expire. If the header doesn't exist, exponential backoff is fine.

And on that note, I'm pretty sure raven-js now can be re-configured at runtime to change the DSN. If so, I think this reconfiguring should reset this backoff and start fresh. Since a new DSN likely would have a different outcome.

Just my thoughts on this. :)

mattrobenolt added a commit to getsentry/sentry that referenced this pull request Jan 26, 2017
XHR requests need this to be able to read our debug headers

See: getsentry/sentry-javascript#839
retry = parseInt(retry, 10);
} catch (e) {
/* eslint no-empty:0 */
}
Copy link
Contributor

Choose a reason for hiding this comment

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

X-Sentry-Error was added too, so you can attempt to fetch this and expose this as a "reason" for debugging and logging.

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 typically appears there?

Copy link
Contributor

Choose a reason for hiding this comment

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

The actual reason.

So an example string would be like:

Invalid project_id: 10

or

Invalid api key

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay. That could be useful for completely different reasons.

(Does Retry-After say something about rate limiting? Or completely independent?)

Copy link
Contributor

Choose a reason for hiding this comment

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

(Does Retry-After say something about rate limiting? Or completely independent?)

This is only related to rate limiting and won't exist on any other response as of today.

mattrobenolt added a commit to getsentry/sentry that referenced this pull request Jan 26, 2017
XHR requests need this to be able to read our debug headers

See: getsentry/sentry-javascript#839
@benvinegar
Copy link
Contributor Author

benvinegar commented Jan 26, 2017

I moved the back off check to run after filters have run ... because, if you were going to filter out an error anyways (e.g. whitelistUrls or shouldSendCallback), you don't need to know that it would have been suppressed from the back off state.

@benvinegar
Copy link
Contributor Author

@mattrobenolt – can you look at this again? I think I've addressed all your feedback (except X-SentryError, which I'd like to follow up with separately).

Copy link
Contributor

@mattrobenolt mattrobenolt 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 to me, but someone who knows js better than me should give final approval.

retry = parseInt(retry, 10);
} catch (e) {
/* eslint no-empty:0 */
}
Copy link
Contributor

Choose a reason for hiding this comment

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

(Does Retry-After say something about rate limiting? Or completely independent?)

This is only related to rate limiting and won't exist on any other response as of today.

@benvinegar benvinegar requested a review from MaxBittker January 27, 2017 21:22
Copy link
Contributor

@MaxBittker MaxBittker left a comment

Choose a reason for hiding this comment

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

looks great

@benvinegar benvinegar merged commit ea58d7f into master Jan 27, 2017
@benvinegar benvinegar deleted the http-429-backoff branch January 27, 2017 21:46
@JTCunning
Copy link

I'm going to look at this PR in about 3 years and be very glad we did this.

Thanks <3

@benvinegar benvinegar mentioned this pull request Mar 23, 2017
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.

4 participants