rocketmq icon indicating copy to clipboard operation
rocketmq copied to clipboard

[Bug] There may be thread safety issues with the brokerVersions Table and brokerAddrTable in MQClientInstance.

Open luozongle01 opened this issue 1 year ago • 0 comments

Before Creating the Bug Report

  • [X] I found a bug, not just asking a question, which should be created in GitHub Discussions.

  • [X] I have searched the GitHub Issues and GitHub 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.

Runtime platform environment

macos: 11.7.10

RocketMQ version

5.3.0

JDK Version

JDK1.8

Describe the Bug

There may be concurrency issues with the value "HashMap<String, Integer>" in the brokerVersionTable of MQClientInstance, such as when a new broker node is added and other threads are getting or traversing the map. Although the likelihood of this happening is relatively low, there is indeed a risk involved. image

Although the brokerAddrTable always replaces the map inside, would it also be better to use Concurrent HashMap. image

Steps to Reproduce

If a new broker is added, when the client obtains the broker version number by sending a heartbeat and puts it into the brokerVersionTable, there may be exceptions if other threads are querying the brokerVersionTable.

What Did You Expect to See?

When adding a broker, both the brokerVersionTable and brokerAddrTable are thread safe

What Did You See Instead?

There may be thread safety issues with brokerVersionTable and brokerAddrTable

Additional Context

No response

luozongle01 avatar Sep 24 '24 08:09 luozongle01