Skip to content

Commit

Permalink
Merge pull request #85 from kickstarter/69-spec-failures
Browse files Browse the repository at this point in the history
Add 1 second buffer to expiry to correct throttles
  • Loading branch information
ktheory committed Sep 9, 2014
2 parents ba52e2c + 074e8e5 commit 8d3e824
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/rack/attack/cache.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ def store=(store)

def count(unprefixed_key, period)
epoch_time = Time.now.to_i
expires_in = period - (epoch_time % period)
# Add 1 to expires_in to avoid timing error: http://git.io/i1PHXA
expires_in = period - (epoch_time % period) + 1
key = "#{prefix}:#{(epoch_time/period).to_i}:#{unprefixed_key}"
do_count(key, expires_in)
end
Expand Down

0 comments on commit 8d3e824

Please sign in to comment.