bottleneck icon indicating copy to clipboard operation
bottleneck copied to clipboard

updateSettings clobbers reservoir increment logic

Open Cireo opened this issue 3 years ago • 6 comments

It appears that updateSettings causes reservoir logic to break, this appears to be true whether or not anything is updated, whether it is run before anything is scheduled or not. The only updates that take place are ones that set reservoir, which are happily consumed (but never refreshed).

bug.js

// updateSettings breaks reservoirIncrease logic (reservoir value is updated)
const Bottleneck = require('bottleneck');

async function foo() {
  const limiter = new Bottleneck({
    reservoir: 5,
    reservoirIncreaseInterval: 1000,
    reservoirIncreaseAmount: 1,
    minTime: 100
  });
  // Takes 5s to log 1->10
  const items = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
  await Promise.all(
    items.map((x) => limiter.schedule(() => console.log(`hi ${x}`)))
  );
  limiter.updateSettings({ reservoir: 5 });
  // Takes .5s to hang/die on 5
  await Promise.all(
    items.map((x) => limiter.schedule(() => console.log(`hi ${x}`)))
  );
}

foo();

Running:

node bottleneckBug.js  
hi 1
hi 2
hi 3
hi 4
hi 5
hi 6
hi 7
hi 8
hi 9
hi 10
hi 1
hi 2
hi 3
hi 4
hi 5

Cireo avatar Apr 16 '21 00:04 Cireo

Hello @SGrondin , do you have any more information on this? Thank you

eugene-kim avatar Oct 20 '21 16:10 eugene-kim

We're also seeing this issue.

kdeclerck avatar Jun 14 '23 09:06 kdeclerck

Facing this issue as well.

louneskmt avatar Nov 16 '23 17:11 louneskmt

I spent like 5 hours trying to debug the code and ended up here facing this very same issue.

fkoemep avatar Feb 20 '24 20:02 fkoemep