SGrondin / bottleneck

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

Unable to share connections #177

Open asafigan opened 3 years ago

asafigan commented 3 years ago

I am using version 2.19.5.

I read through all of your documentation on share connections. Each suggested way causes the limiter to never execute a job once it hits any type of limit.

Here is how I am creating the connection currently:

function createBottleneckConnection({
  redisUrl,
}) {
  const limiter = new Bottleneck({
    id: 'setup',
    datastore: 'ioredis',
    clientOptions: redisUrl
  })
  const connection = limiter.connection
  if (!connection) {
    throw new Error('no connection')
  }

  return connection
}

Here is how I am using the connection:

  const settings = {
    id,
    reservoir,
    reservoirRefreshAmount: reservoir,
    reservoirRefreshInterval,
    maxConcurrent,
    minTime,
  }

  const limiter = new Bottleneck({
    ...settings,
    connection,
    clearDatastore: false,
  })

If I just change it to:

  const limiter = new Bottleneck({
    ...settings,
    datastore: "ioredis",
    clientOptions: redisUrl,
    clearDatastore: false,
  })

It works fine.

I have also tried creating a Bottleneck.IORedisConnection directly using both a client and clientOptions. All of them cause the limiters to fail in the same way.