[ISSUE #10690] Tolerate malformed SimpleChannel address ports - #10691
[ISSUE #10690] Tolerate malformed SimpleChannel address ports#10691Aias00 wants to merge 3 commits into
Conversation
RockteMQ-AI
left a comment
There was a problem hiding this comment.
Review by github-manager-bot
Summary
Defensive fix: SimpleChannel.parseSocketAddress now catches NumberFormatException on malformed port values and returns null instead of propagating the exception. Includes a new unit test.
Findings
-
[Info]
proxy/src/main/java/org/apache/rocketmq/proxy/service/channel/SimpleChannel.java:93-96— Thelog.warnmessage could include the exception message (e.getMessage()) to aid debugging, e.g."parse socket address failed. address:{}, error:{}". Minor, non-blocking. -
[Info]
proxy/src/test/java/org/apache/rocketmq/proxy/service/channel/SimpleChannelTest.java— Test coverage looks good. Covers valid address parsing, null/empty input, wrong segment count, and malformed port. Consider also testing with an empty port string ("127.0.0.1:") sinceInteger.parseInt("")also throwsNumberFormatException.
Overall
Clean, focused fix with appropriate test coverage. The approach of catching NumberFormatException and returning null is consistent with the existing invalid-address handling pattern. LGTM.
Automated review by github-manager-bot
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## develop #10691 +/- ##
=============================================
- Coverage 48.32% 48.23% -0.09%
+ Complexity 13512 13488 -24
=============================================
Files 1380 1380
Lines 101091 101115 +24
Branches 13101 13102 +1
=============================================
- Hits 48851 48774 -77
- Misses 46279 46349 +70
- Partials 5961 5992 +31 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
[P1] The malformed-port handling is incomplete for out-of-range values. The new catch handles Please validate the parsed port explicitly as Please add assertions for |
RockteMQ-AI
left a comment
There was a problem hiding this comment.
Review by github-manager-bot (Re-review)
PR #10691: [ISSUE #10690] Tolerate malformed SimpleChannel address ports
Re-review trigger: New maintainer feedback from @fuyou001 (2026-07-30)
Maintainer Feedback Summary
@fuyou001 raised a P1 correctness concern: the catch (NumberFormatException) only handles non-numeric port strings, but values like 127.0.0.1:-1 and 127.0.0.1:65536 parse successfully as integers. The InetSocketAddress constructor then throws IllegalArgumentException for out-of-range ports, which is not caught — so remoteAddress() and localAddress() can still throw for malformed input.
Assessment
The concern is valid. The current fix is incomplete:
try {
return new InetSocketAddress(segments[0], Integer.parseInt(segments[1]));
} catch (NumberFormatException e) {
log.warn("parse socket address failed. address:{}", address);
return null;
}Integer.parseInt("-1") succeeds → InetSocketAddress("127.0.0.1", -1) throws IllegalArgumentException → uncaught → propagates up.
Similarly, Integer.parseInt("65536") succeeds but InetSocketAddress rejects it.
Suggested Fix Direction
Two options (prefer option 1 for clearer semantics):
- Validate port range explicitly before constructing the address:
int port = Integer.parseInt(segments[1]);
if (port < 0 || port > 65535) {
log.warn("port out of range: {}", address);
return null;
}
return new InetSocketAddress(segments[0], port);- Also catch
IllegalArgumentException:
} catch (NumberFormatException | IllegalArgumentException e) {
log.warn("parse socket address failed. address:{}", address);
return null;
}Suggested Test Cases
Add assertions for: -1, 65536, Integer.MAX_VALUE + 1 (overflow), empty port, whitespace port — covering both remoteAddress() and localAddress().
Status
No new commits since the maintainer feedback. Awaiting author response.
Automated review by github-manager-bot
|
Addressed the malformed-port caller coverage in Changes:
Local verification passed: |
RockteMQ-AI
left a comment
There was a problem hiding this comment.
Review by github-manager-bot (Re-review after new commits)
PR #10691: [ISSUE #10690] Tolerate malformed SimpleChannel address ports
Re-review trigger: New commits pushed on Jul 31 (after previous review on Jul 31 00:37)
Previous P1 Concern Resolution
The previous review raised a P1 correctness concern: out-of-range ports like -1 or 65536 could parse as integers but throw IllegalArgumentException from InetSocketAddress, which was not caught.
✅ Fully resolved. The new commits add defense in depth:
SimpleChannel.parseSocketAddress— validates port range (0-65535) before constructingInetSocketAddress. Invalid ports returnnullwith a warning log.ProxyChannel.socketAddress2String— wrapssocketAddress2Stringwith try-catch forRuntimeException, returning the raw string on failure.ContextInitPipeline.socketAddress2String— same defensive wrapper for the pipeline path.RemotingChannel— switched fromNetworkUtil.socketAddress2StringtoProxyChannel.socketAddress2Stringfor consistent behavior.
Code Quality
- Port range validation:
port < 0 || port > 65535check is correct ✓ - Defensive layers: Multiple catch points ensure no uncaught
IllegalArgumentExceptionpropagates ✓ - Logging: Warning logs for malformed addresses aid diagnostics ✓
- Tests: Comprehensive coverage including
127.0.0.1:-1,127.0.0.1:65536,127.0.0.1:abc, and blank addresses ✓
Minor Observation
There is code duplication in socketAddress2String — defined in both ProxyChannel and ContextInitPipeline. Consider extracting to a shared utility (e.g., NetworkUtil) in a follow-up. This is a style concern, not a blocker.
Verdict
Approve. The P1 correctness concern is fully addressed with proper port range validation and defensive exception handling.
RockteMQ-AI
left a comment
There was a problem hiding this comment.
Summary
Defensive fix with proper validation and test coverage. LGTM.
Automated review by github-manager-bot
Which Issue(s) This PR Fixes
Fixes #10690
Brief Description
SimpleChannel.parseSocketAddressalready returnsnullfor blank addresses and strings that do not matchhost:port, but it directly parsed the port when two segments were present. A malformed value such as127.0.0.1:not-a-portcould makeremoteAddress()orlocalAddress()throwNumberFormatException.This PR makes malformed port values follow the same invalid-address behavior by returning
null, with a diagnostic warning. Valid addresses keep the existing behavior.How Did You Test This Change?
mvn -pl proxy -Dtest=SimpleChannelTest -DfailIfNoTests=false testResult:
BUILD SUCCESS,Tests run: 2, Failures: 0, Errors: 0, Skipped: 0.