node-rate-limiter-flexible icon indicating copy to clipboard operation
node-rate-limiter-flexible copied to clipboard

key column length (256 chars) makes problem in long key rate limitation in postgres

Open KeyvanArj opened this issue 3 years ago • 1 comments

The key column in the generated table by RateLimiterPostgres is defined in this way:

character varying (256)

So when the length of selected key is bigger than 256 characters, it fails, without any log and just returns 429!!!

I've used SHA-256 hash function to create 256 characters-key to make sure that it never fails

KeyvanArj avatar Jun 05 '22 13:06 KeyvanArj

@KeyvanArj Hey, that's interesting case, thank you for reporting.

While SHA-256 solution is good, there is another one I could suggest. Database table can be created separately from RateLimiterPostgres with any scheme you wish. There is tableCreated option, which should be set to true during rate limiter creation.

Anyway, it shouldn't throw 429. Could you share your code, which processes rejected consume call?

animir avatar Jun 05 '22 15:06 animir

Closing this, since it is not a bug and there are at least two ways to solve this edge case.

animir avatar Aug 06 '22 21:08 animir