Skip to content

Commit a1eb7dc

Browse files
Don't scale down on error if we have never seen a poller decision (#2575)
1 parent 68e4c4c commit a1eb7dc

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

temporal-sdk/src/main/java/io/temporal/internal/worker/PollScaleReportHandle.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ public PollScaleReportHandle(
3636

3737
public synchronized void report(T task, Throwable e) {
3838
if (e != null) {
39+
// We want to avoid scaling down on errors if we have never seen a scaling decision
40+
// since we might never scale up again.
41+
if (!everSawScalingDecision) {
42+
return;
43+
}
3944
if ((e instanceof StatusRuntimeException)) {
4045
StatusRuntimeException statusRuntimeException = (StatusRuntimeException) e;
4146
if (statusRuntimeException.getStatus().getCode() == Status.Code.RESOURCE_EXHAUSTED) {

temporal-sdk/src/test/java/io/temporal/internal/worker/PollScaleReportHandleTest.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,16 @@ public class PollScaleReportHandleTest {
1212
public void handleResourceExhaustedError() {
1313
// Mock dependencies
1414
Functions.Proc1<Integer> mockScaleCallback = Mockito.mock(Functions.Proc1.class);
15+
ScalingTask mockTask = Mockito.mock(ScalingTask.class);
16+
ScalingTask.ScalingDecision mockDecision = Mockito.mock(ScalingTask.ScalingDecision.class);
17+
Mockito.when(mockTask.getScalingDecision()).thenReturn(mockDecision);
18+
Mockito.when(mockDecision.getPollRequestDeltaSuggestion()).thenReturn(0);
1519
PollScaleReportHandle<ScalingTask> handle =
1620
new PollScaleReportHandle<>(1, 10, 8, mockScaleCallback);
1721

1822
// Simulate RESOURCE_EXHAUSTED error
1923
StatusRuntimeException exception = new StatusRuntimeException(Status.RESOURCE_EXHAUSTED);
24+
handle.report(mockTask, null);
2025
handle.report(null, exception);
2126

2227
// Verify target poller count is halved and callback is invoked
@@ -27,10 +32,15 @@ public void handleResourceExhaustedError() {
2732
public void handleGenericError() {
2833
// Mock dependencies
2934
Functions.Proc1<Integer> mockScaleCallback = Mockito.mock(Functions.Proc1.class);
35+
ScalingTask mockTask = Mockito.mock(ScalingTask.class);
36+
ScalingTask.ScalingDecision mockDecision = Mockito.mock(ScalingTask.ScalingDecision.class);
37+
Mockito.when(mockTask.getScalingDecision()).thenReturn(mockDecision);
38+
Mockito.when(mockDecision.getPollRequestDeltaSuggestion()).thenReturn(0);
3039
PollScaleReportHandle<ScalingTask> handle =
3140
new PollScaleReportHandle<>(1, 10, 5, mockScaleCallback);
3241

3342
// Simulate a generic error
43+
handle.report(mockTask, null);
3444
handle.report(null, new RuntimeException("Generic error"));
3545

3646
// Verify target poller count is decremented and callback is invoked

0 commit comments

Comments
 (0)