Before Creating the Bug Report
Runtime platform environment
All platforms
RocketMQ version
develop branch (latest)
JDK Version
All
Describe the Bug
In DefaultHAConnection (line 64) and AutoSwitchHAConnection (line 109), .toString() is called directly on the return value of getRemoteSocketAddress() without a null check:
this.clientAddress = this.socketChannel.socket().getRemoteSocketAddress().toString();
According to the Java documentation, Socket.getRemoteSocketAddress() returns null if the socket is not connected. In edge cases (e.g., the socket is accepted but the remote peer disconnects before the HA connection constructor completes), this can throw a NullPointerException, which would crash the HA connection setup.
Steps to Reproduce
- Under network instability, a slave connects and immediately disconnects
- The master accepts the socket channel
DefaultHAConnection constructor is called
getRemoteSocketAddress() returns null because the peer has already disconnected
.toString() on null throws NPE
What Did You Expect to See?
The HA connection should handle null remote address gracefully.
What Did You See Instead?
NullPointerException in the HA connection constructor.
Additional Context
Affected files:
store/src/main/java/org/apache/rocketmq/store/ha/DefaultHAConnection.java:64
store/src/main/java/org/apache/rocketmq/store/ha/autoswitch/AutoSwitchHAConnection.java:109
Before Creating the Bug Report
Runtime platform environment
All platforms
RocketMQ version
develop branch (latest)
JDK Version
All
Describe the Bug
In
DefaultHAConnection(line 64) andAutoSwitchHAConnection(line 109),.toString()is called directly on the return value ofgetRemoteSocketAddress()without a null check:According to the Java documentation,
Socket.getRemoteSocketAddress()returnsnullif the socket is not connected. In edge cases (e.g., the socket is accepted but the remote peer disconnects before the HA connection constructor completes), this can throw aNullPointerException, which would crash the HA connection setup.Steps to Reproduce
DefaultHAConnectionconstructor is calledgetRemoteSocketAddress()returns null because the peer has already disconnected.toString()on null throws NPEWhat Did You Expect to See?
The HA connection should handle null remote address gracefully.
What Did You See Instead?
NullPointerException in the HA connection constructor.
Additional Context
Affected files:
store/src/main/java/org/apache/rocketmq/store/ha/DefaultHAConnection.java:64store/src/main/java/org/apache/rocketmq/store/ha/autoswitch/AutoSwitchHAConnection.java:109