Skip to content

fix: prevent infinite loop in balanceHighestNode on selector error#895

Merged
mattisonchao merged 1 commit intomainfrom
fix/lb-infinite-loop
Feb 24, 2026
Merged

fix: prevent infinite loop in balanceHighestNode on selector error#895
mattisonchao merged 1 commit intomainfrom
fix/lb-infinite-loop

Conversation

@mattisonchao
Copy link
Copy Markdown
Member

Motivation

In balanceHighestNode, when swapShard returned a non-nil error, continue skipped shardIter.Prev(). The iterator stayed on the same shard, retrying it forever. This hangs the balancer goroutine. Happens when anti-affinity is Strict and no valid placement exists.

Modification

  • Always advance the shard iterator regardless of swap result by removing the continue after the error log
  • Add reproduction test TestBalanceHighestNodeDoesNotHangOnSelectorError using a selector that always returns ErrUnsatisfiedAntiAffinity, verifying rebalanceEnsemble() completes without hanging

When swapShard returned an error, the continue statement skipped
shardIter.Prev(), leaving the iterator on the same shard. This caused
the loop to retry the same shard forever, hanging the balancer goroutine.

Always advance the shard iterator regardless of the swap result.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@mattisonchao mattisonchao marked this pull request as draft February 23, 2026 16:51
@mattisonchao mattisonchao marked this pull request as ready for review February 24, 2026 08:33
@mattisonchao mattisonchao merged commit e2973b8 into main Feb 24, 2026
15 of 18 checks passed
@mattisonchao mattisonchao deleted the fix/lb-infinite-loop branch February 24, 2026 09:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants