SGrondin / bottleneck

Job scheduler and rate limiter, supports Clustering
MIT License
1.84k stars 79 forks source link

Getting Error Running Script #183

Open thelaughingwolf opened 3 years ago

thelaughingwolf commented 3 years ago

I'm getting an error from Redis on limiter startup. I've seen this error before, but I resolved it by using clearDatastore: true and restarting. I don't want to wipe out the shared limiter configuration every time an instance of my app restarts, though.

Error:

ReplyError: ERR Error running script (call to f_f015b372dc34d68d4d08ea116eac3307c8602945): @user_script:250: ERR value is not an integer or out of range 
    at new Command (/opt/ws/webapps/apiv3/node_modules/redis/lib/command.js:12:22)
    at RedisClient.evalsha (/opt/ws/webapps/apiv3/node_modules/redis/lib/commands.js:46:47)
    at _this3.Promise (/opt/ws/webapps/apiv3/node_modules/bottleneck/lib/RedisDatastore.js:174:52)
    at new Promise (<anonymous>)
    at /opt/ws/webapps/apiv3/node_modules/bottleneck/lib/RedisDatastore.js:161:14
    at Generator.next (<anonymous>)
    at asyncGeneratorStep (/opt/ws/webapps/apiv3/node_modules/bottleneck/lib/RedisDatastore.js:11:103)
    at _next (/opt/ws/webapps/apiv3/node_modules/bottleneck/lib/RedisDatastore.js:13:194)
    at process._tickCallback (internal/process/next_tick.js:68:7)

Non-sensitive config:

{ maxConcurrent: 5,
  minTime: 0,
  reservoir: 700,
  reservoirRefreshAmount: 700,
  reservoirRefreshInterval: 60000,
  id: ********, // Not an integer, nor, per documentation, expected to be
  datastore: 'redis',
  clearDatastore: false,
  timeout: 300000,
  clientOptions:
   { host: 'dev-ws-redis1.mqa.boingo.com',
     port: '10001',
     password: ******** } }

I saw this error, then I removed the id option and my app connected. Then I restored id and my app connected again. I don't have any idea how to explain this behavior, since all I did was remove and restore the ID, and it's concerning that my app simply won't start sometimes.

thelaughingwolf commented 3 years ago

The error is persisting across multiple hosts. I can temporarily resolve the issue by changing the ID, but after enough restarts and reconnects, the error will appear again and I have to update the ID to get it to work.

I have tried with both datastore: "redis" and datastore: "ioredis". Also, clearDatastore: true appears to have no effect.

thelaughingwolf commented 3 years ago

Given this behavior, we're unable to rely on this package for any real-world applications. I've used Bottleneck without problems before, and according to the documentation, this package is relied upon in many demanding environments, but it's consistently breaking down for us.

Can anyone provide any guesses or suggestions? I don't see any alternatives to Bottleneck's limiting behavior.

tylergeery commented 3 years ago

In case this helps somebody. I have been running into this error today on version 2.19.5. I have figured out why it's happening in our case

the minTime provided in the config was a Float (calculated as 12.5)

new Bottleneck.Group({id: 'test', minTime: 12.5 }

below are the commands from redis monitor that helped me track it down. Looks like this float eventually coerces the millisecond time to pexpire to be a float as well.


1618273385.366529 [15 lua] "zadd" "b_test-test_client_last_registered" "1618273385366" "cl6rj00kshg"
1618273385.366540 [15 lua] "hset" "b_test-test_settings" "nextRequest" "1618273385378.5"
1618273385.366549 [15 lua] "pexpire" "b_test-test_settings" "300012.5"