You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@rocketmq.apache.org by ji...@apache.org on 2026/08/10 07:07:50 UTC

(rocketmq-clients) branch master updated: [Go] Fix round-robin load balancer always selecting the same queue (#1324)

This is an automated email from the ASF dual-hosted git repository.

RongtongJin pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/rocketmq-clients.git


The following commit(s) were added to refs/heads/master by this push:
     new f790a484 [Go] Fix round-robin load balancer always selecting the same queue (#1324)
f790a484 is described below

commit f790a484f8e9124ada52ed20be73bc5c4f2e7758
Author: guyinyou <36...@users.noreply.github.com>
AuthorDate: Mon Aug 10 15:07:43 2026 +0800

    [Go] Fix round-robin load balancer always selecting the same queue (#1324)
    
    * [Go] Fix round-robin load balancer always selecting the same queue
    
    In TakeMessageQueues, the index was computed as `next+1` (constant)
    instead of `next+i` (loop-varying), causing every loop iteration to
    examine the same message queue. This defeats the round-robin intent
    and prevents proper load distribution across brokers.
    
    * [Go] Fix int32/int type mismatch in load balancer index calculation
    
    ---------
    
    Co-authored-by: guyinyou <gu...@alibaba-inc.com>
---
 golang/loadBalancer.go | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/golang/loadBalancer.go b/golang/loadBalancer.go
index 9e2e5b88..ae6c297f 100644
--- a/golang/loadBalancer.go
+++ b/golang/loadBalancer.go
@@ -73,7 +73,7 @@ func (plb *publishingLoadBalancer) TakeMessageQueues(excluded *sync.Map, count i
 	candidateBrokerNames := make(map[string]bool, 32)
 
 	for i := 0; i < len(plb.messageQueues); i++ {
-		idx := utils.Mod(next+1, len(plb.messageQueues))
+		idx := utils.Mod(next+int32(i), len(plb.messageQueues))
 		selectMessageQueue := plb.messageQueues[idx]
 		broker := selectMessageQueue.Broker
 		brokerName := broker.GetName()
@@ -102,7 +102,7 @@ func (plb *publishingLoadBalancer) TakeMessageQueues(excluded *sync.Map, count i
 	}
 	if len(candidates) == 0 {
 		for i := 0; i < len(plb.messageQueues); i++ {
-			idx := utils.Mod(next+1, len(plb.messageQueues))
+			idx := utils.Mod(next+int32(i), len(plb.messageQueues))
 			selectMessageQueue := plb.messageQueues[idx]
 			broker := selectMessageQueue.Broker
 			brokerName := broker.GetName()