You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@rocketmq.apache.org by di...@apache.org on 2021/04/16 09:40:36 UTC

[rocketmq-client-go] branch master updated: fix crash on selecting queue. (#643)

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

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


The following commit(s) were added to refs/heads/master by this push:
     new 2d513f3  fix crash on selecting queue. (#643)
2d513f3 is described below

commit 2d513f35514e700da960b6c0c97ffcc4e0bc0382
Author: NAND86 <32...@users.noreply.github.com>
AuthorDate: Fri Apr 16 17:40:26 2021 +0800

    fix crash on selecting queue. (#643)
---
 producer/selector.go | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/producer/selector.go b/producer/selector.go
index 1aead8b..69d216f 100644
--- a/producer/selector.go
+++ b/producer/selector.go
@@ -44,6 +44,7 @@ func (manualQueueSelector) Select(message *primitive.Message, queues []*primitiv
 
 // randomQueueSelector choose a random queue each time.
 type randomQueueSelector struct {
+	mux    sync.Mutex
 	rander *rand.Rand
 }
 
@@ -53,8 +54,10 @@ func NewRandomQueueSelector() QueueSelector {
 	return s
 }
 
-func (r randomQueueSelector) Select(message *primitive.Message, queues []*primitive.MessageQueue) *primitive.MessageQueue {
+func (r *randomQueueSelector) Select(message *primitive.Message, queues []*primitive.MessageQueue) *primitive.MessageQueue {
+	r.mux.Lock()
 	i := r.rander.Intn(len(queues))
+	r.mux.Unlock()
 	return queues[i]
 }