@@ -335,18 +335,20 @@ void resize() {
335335 int delta = tentativeTarget - currentSize ;
336336 int dampenedTarget = tentativeTarget ;
337337 // Dampen the rate of change if the desired delta exceeds the maximum allowed step size.
338- // Ensure that the step size is capped by the max channel count to handle small pool
339- // configurations.
338+ // Ensure that the step size is capped by the max channel count.
339+ // Note: resize delta value is not enforced to be smaller than max channel count in
340+ // ChannelPoolSettings as DEFAULT_RESIZE_DELTA is 2 and max channel pool count can be 1
340341 int effectiveMaxResizeDelta =
341342 Math .min (settings .getMaxResizeDelta (), settings .getMaxChannelCount ());
343+ // Rate-limit the change to not exceed the effectiveMaxResizeDelta
342344 if (Math .abs (delta ) > effectiveMaxResizeDelta ) {
343- // Limit the change to effectiveMaxResizeDelta, maintaining the correct direction (positive or
344- // negative).
345- dampenedTarget = currentSize + ( int ) Math . copySign ( effectiveMaxResizeDelta , delta ) ;
345+ // Maintaining the correct direction (positive or negative) to handle expand/shrink
346+ int step = delta > 0 ? effectiveMaxResizeDelta : - effectiveMaxResizeDelta ;
347+ dampenedTarget = currentSize + step ;
346348 }
347349
348- // Ensure that the calculated dampedTarget value will never exceed the maxChannelCount or fall
349- // below minChannelCount
350+ // Ensure that the calculated dampenedTarget value will never exceed the maxChannelCount or fall
351+ // below minChannelCount. This ensures that `currentSize + resizeDelta` remains within bounds.
350352 dampenedTarget =
351353 Math .max (
352354 settings .getMinChannelCount (), Math .min (settings .getMaxChannelCount (), dampenedTarget ));
0 commit comments