-
-
Notifications
You must be signed in to change notification settings - Fork 158
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
Using RateLimiterPostgres + knex.js yields wrong data in db #95
Comments
@noamackerman-monday Hi, it looks like a bug. I am quite busy now, I am going to look at it over the next weekend. If you need a fix earlier, you can try search a bug from this block of code
|
@noamackerman-monday I fixed this bug and published patched Why do you need to know consumedPoints after block, btw? Just curious about your use case. |
@animir Amazing thanks! |
Hi,
When using the RateLimiterPostgres + knex.js, i'm seeing wrong results written to the db when the points limit is exceeded.
Code:
const {RateLimiterPostgres} = require('rate-limiter-flexible');
let options = { storeClient: connection, storeType:
knex, points: 2, duration: 0, blockDuration: 60 * 60 * 24 * 365, tableName: 'downloads_rate_limiter', keyPrefix: 'downloadsrl', inmemoryBlockOnConsumed: 2, inmemoryBlockDuration: 60 * 60 * 24 * 365, tableCreated: true };
const rateLimiter = new RateLimiterPostgres(options);
app.get('/hello', async (req, res) => {
try { await rateLimiter.consume(obj, 1); doSomeOperation(); } catch (error) { if (error instanceof Error) { // Some Postgres error // Never happen if
insuranceLimiterset up res.writeHead(500) } else { // Can't consume res.writeHead(429); } res.end(error.toString()) }
});
Now let's say i'm calling the 'hello' endpoint 3 times and looking the at points column in the db. After the first 2 times i will see the value 2, which is expected, but at the 3rd time and on i will start to see some random value, jumping from 2 to 6, then to 9 and 12 etc.
Can you please help me understand what is the reason for this behaviour? Seems like a bug.
Thanks!
Noam
The text was updated successfully, but these errors were encountered: