apache / apache/rocketmq-clients

[Bug][Go] Producer may send messages to read-only slave brokers

Open
#1,345 4 comments 0 reactions 0 assignees View on GitHub
type/bug
Dominant language
Java
Stars
505
Forks
313
Avg merge
11h 28m
Merged PRs (30d)
6

Description

### Before Creating the Bug Report

- [x] I found a bug, not just asking a question, which should be created in [GitHub Discussions](https://github.com/apache/rocketmq-clients/discussions).

- [x] I have searched the [GitHub Issues](https://github.com/apache/rocketmq-clients/issues) and [GitHub Discussions](https://github.com/apache/rocketmq-clients/discussions) of this repository and believe that this is not a duplicate.

- [x] I have confirmed that this bug belongs to the current repository, not other repositories of RocketMQ.

### Programming Language of the Client

Go

### Runtime Platform Environment

Linux

### RocketMQ Version of the Client/Server

Client: golang/v5.1.2, v5.1.3, v5.1.4 and current master
Server: RocketMQ 5.x compatible server

### Run or Compiler Version

Go 1.24+

### Describe the Bug

The Go Producer does not filter message queues by broker role and write permission in `NewPublishingLoadBalancer` or `CopyAndUpdate`.
When the route contains slave queues, the Producer may select a slave and attempt to send messages to it.
The Java SDK already filters publishing queues using:
```Java
mq.getPermission().isWritable()
&& Utilities.MASTER_BROKER_ID == mq.getBroker().getId()
```

### Steps to Reproduce

Create a route containing a writable master queue and a slave queue, then call:
```Go
loadBalancer, _ := NewPublishingLoadBalancer(queues)
candidates, _ := loadBalancer.TakeMessageQueues(&sync.Map{}, len(queues))
```
The returned candidates may contain the slave queue. The same issue occurs after `CopyAndUpdate`.

### What Did You Expect to See?

The Producer should only select queues that satisfy:
```Go
mq.GetBroker().GetId() == 0 &&
(mq.GetPermission() == v2.Permission_WRITE ||
mq.GetPermission() == v2.Permission_READ_WRITE)
```
If no writable master exists, queue selection should fail.

### What Did You See Instead?

The Producer may select a slave queue. The server then rejects the request with an error similar to:
```text
service not available now ... messages are put to the slave
```

### Additional Context

This issue was reproduced in a RocketMQ 5.x-compatible environment. Filtering slave and non-writable queues resolved the send failure. The fix should cover both initial route creation and route refresh.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start at NewPublishingLoadBalancer and CopyAndUpdate, which the issue identifies as the route setup and refresh paths. Reproduce the case with one writable master queue and one slave queue, then verify that TakeMessageQueues returns only queues with broker ID 0 and write permission; selection should fail when no writable master exists.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
distributed-systems
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
70/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.