Description
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
insuranceLimiter set 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
Activity