Skip to content

Add 1 second buffer to expiry to correct throttles#85

Merged
ktheory merged 1 commit intomasterfrom
69-spec-failures
Sep 9, 2014
Merged

Add 1 second buffer to expiry to correct throttles#85
ktheory merged 1 commit intomasterfrom
69-spec-failures

Conversation

@ktheory
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Collaborator Author

ktheory commented Sep 2, 2014

Thanks @zmillman. Added a comment to the commit.

@zmillman
Copy link
Copy Markdown
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