Comments (4)
If by chance there two requests do come in at the same time (in a concurrent app) it is possible for them to both read the value of the current count as the same, and increment them equally. I.E what happened at request 13/15 for you. This probably isn't the best! Though, I believe in order to fix this you should have a "concurrent-resistant" cache.
I think there is some more concurrency safety nets that are needed for the concurrently safe cache to work, though rolling your own cache get/set might be a good solution.
from rack-throttle.
@FreekingDean Just tried to solve the same problem in our application, but the only safe way to do this is to have both the get and set happen within the same critical section. In other words, even if the get and set operations are each thread-safe, reading and then writing back a value is not because the entire operation does not happen within a lock.
Something is needed at the top level -- in Rack Throttle -- to handle this.
from rack-throttle.
Another option would be for the cache implementation to provide an increment
method, which Rack Throttle can use to fetch, increment, and set the value in a single operation. That would allow the cache to provide a thread-safe, atomic way to handle this.
from rack-throttle.
Right, unfortunately this would require some cache-specific code. Though it could be "stubbed" out for a more generic get/set and allowed to be over-ridden via cache specific code.
from rack-throttle.
Related Issues (20)
- Release with Rack::Throttle::Second? HOT 1
- Custom responses? HOT 3
- Change client identification HOT 5
- Use HTTP Status 429 - Too Many Requests HOT 9
- Problem with version and rubygems HOT 2
- use different rate-limiting for controllers HOT 2
- No tag for 0.4.0 HOT 9
- NameError: uninitialized constant Rack::Throttle::Second HOT 1
- Are API requests not being a subject to throttling? HOT 1
- Missing minute directive in second.rb cache_key HOT 1
- Add cache expiration for Redis HOT 5
- Key conflict when combining various throttling constraints into one overall policy HOT 2
- uninitialized constant Rack::Throttle::Limiter (NameError) HOT 1
- Request - add documentation/support for using with Grape API's HOT 2
- Clearing Cache HOT 1
- Deprecate in favor of RackAttack HOT 3
- ActiveSupport::Cache::MemCacheStore unsupported HOT 5
- README in latest release & tagging HOT 1
- Wrong request IP determined in container/proxy context
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rack-throttle.