node-rate-limiter-flexible: TypeError: Cannot read properties of null (reading 'points') using mongoose
Getting an error issue with ratelimiter, this error happens once if the IP connects for the first time and any subsequent connection the rate-limiter will work correctly.
TypeError: Cannot read properties of null (reading 'points')
at RateLimiterMongo._getRateLimiterRes (\user\node_modules\rate-limiter-flexible\lib\RateLimiterMongo.js:124:33)
at RateLimiterMongo._afterConsume (\user\node_modules\rate-limiter-flexible\lib\RateLimiterStoreAbstract.js:51:22)
at \user\node_modules\rate-limiter-flexible\lib\RateLimiterStoreAbstract.js:263:16
at processTicksAndRejections (node:internal/process/task_queues:96:5)
I am using mongoose 6.5.3 under serverless instance, (do note that this issue also occurs on shared instances.)
About this issue
- Original URL
- State: open
- Created 3 years ago
- Reactions: 1
- Comments: 15 (6 by maintainers)
my issue was fixed in 4.0.1, see: https://github.com/animir/node-rate-limiter-flexible/issues/251.
jumping on this question because im seeing a similar issue and was wondering if it had to do with buffering.
I see error
Cannot read properties of null (reading 'value')when the first call is made, and every call after succeeds as long as the entry in the database hasnt been deleted for that key.Is this a bug with the rate limiter that isnt handling null from the value properly on the first call, it should expect that the first call will not have any entry in the database.
edit: adding context
using rate limiter with the following setup
@animir for vis
Found the root cause, mongoDB in the examples works flawlessly due to
.connect()actually creates multiple connection pools and manages the database on those multiple connections. The downside is that we can only use it once. To mitigate this issue we would have to usecreateConnection().Unlike
.connect(),createConnection()only creates 1 connection, so we would lose out on the automatic connection pool management from the .connect() therefore we would need to manage it ourselves.Although this solution above works, it is a stretch especially when you already have your workflow arranged.
my solution to this problem is to simply wait for the database to connect before creating a RateLimitMongo instance