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

Add 1 second buffer to expiry to correct throttles #85

Merged
merged 1 commit into from
Sep 9, 2014

Conversation

ktheory
Copy link
Collaborator

@ktheory ktheory commented Aug 31, 2014

Fixes #69.

There was a race condition when Time.now.to_i changes between when
epoch_time is computed in line 18, and the cache request is made (and
the key is expired).

I.e., a throttle check starts at t0, but doesn’t reach the cache until
t1, the cache will have expired the throttle count. The request will
likely be allowed, even if the request exceeded the limit.

This has the effect of keeping keys in cache about 1 second longer than
strictly necessary. But the extra cache space seems like a good
trade-off for correct throttling.

Looking for a sanity check/:+1: from @zmillman before merging.

@zmillman
Copy link
Contributor

zmillman commented Sep 2, 2014

The logic looks sound to me, but without the context of this pull request the extra + 1 looks like magic ✨

A comment explaining why it's there or a reference to this PR would be nice :)

Fixes #69.

There was a race condition when `Time.now.to_i` changes between when
`epoch_time` is computed in line 18, and the cache request is made (and
the `key` is expired).

I.e., a throttle check starts at t0, but doesn’t reach the cache until
t1, the cache will have expired the throttle count. The request will
likely be allowed, even if the request exceeded the limit.

This has the effect of keeping keys in cache about 1 second longer than
strictly necessary. But the extra cache space seems like a good
trade-off for correct throttling.
@ktheory
Copy link
Collaborator Author

ktheory commented Sep 2, 2014

Thanks @zmillman. Added a comment to the commit.

@zmillman
Copy link
Contributor

zmillman commented Sep 2, 2014

👍

ktheory added a commit that referenced this pull request Sep 9, 2014
Add 1 second buffer to expiry to correct throttles
@ktheory ktheory merged commit 8d3e824 into master Sep 9, 2014
@ktheory ktheory deleted the 69-spec-failures branch September 9, 2014 01:28
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.

Specs failing at random intervals
2 participants