Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion controller/appcontroller.go
Original file line number Diff line number Diff line change
Expand Up @@ -2143,7 +2143,8 @@ func (ctrl *ApplicationController) shouldSelfHeal(app *appv1.Application) (bool,
backOff := *ctrl.selfHealBackOff
backOff.Steps = int(app.Status.OperationState.Operation.Sync.SelfHealAttemptsCount)
var delay time.Duration
for backOff.Steps > 0 {
steps := backOff.Steps
Copy link
Copy Markdown
Member

@pasha-codefresh pasha-codefresh Dec 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it happens because

next = time.Duration(float64(duration) * factor)
		if cap > 0 && next > cap {
			next = cap
			steps = 0
		}

Inside backoff library, it is marking steps as 0 and setup next with correct value, and just because of backOff.Steps > 0 we never reach last iteration.

Just leaving as explanation for future

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You still potentially can pass max int value as backoff , but it will not have any performance impact, because here exit in the function if steps are 0

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hovewer we can change the loop a bit, but i think it is overcomplicate it without significant benefit

for i := 0; i < steps; i++ {
	delay = backOff.Step()
	
	if i != steps - 1 && backOff.Steps == 0 {
		delay = backOff.Duration
		break
	}
	
}

for i := 0; i < steps; i++ {
delay = backOff.Step()
}
if app.Status.OperationState.FinishedAt == nil {
Expand Down
17 changes: 16 additions & 1 deletion controller/appcontroller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2205,7 +2205,7 @@ func TestSelfHealExponentialBackoff(t *testing.T) {
ctrl.selfHealBackOff = &wait.Backoff{
Factor: 3,
Duration: 2 * time.Second,
Cap: 5 * time.Minute,
Cap: 2 * time.Minute,
}

app := &v1alpha1.Application{
Expand Down Expand Up @@ -2243,6 +2243,21 @@ func TestSelfHealExponentialBackoff(t *testing.T) {
finishedAt: nil,
expectedDuration: 18 * time.Second,
shouldSelfHeal: false,
}, {
attempts: 4,
finishedAt: nil,
expectedDuration: 54 * time.Second,
shouldSelfHeal: false,
}, {
attempts: 5,
finishedAt: nil,
expectedDuration: 120 * time.Second,
shouldSelfHeal: false,
}, {
attempts: 6,
finishedAt: nil,
expectedDuration: 120 * time.Second,
shouldSelfHeal: false,
}}

for i := range testCases {
Expand Down