You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Track connection-pool entries by Channel instance when different TCP channels have the same remote InetSocketAddress.
Keep active/passive peer counters aligned with the channel that is being connected or disconnected.
Prevent same-address channels from being collapsed by Channel.equals() during pool lifecycle bookkeeping.
Why are these changes required?
Channel.equals() currently identifies a channel only by its remote socket address. If the remote host supports TCP source-port reuse and uses its listening port as the source port of an inbound connection, an inbound and an outbound channel can have the same remote address while remaining different TCP connections.
The pool could then skip counting the second channel, but later decrement the counter according to the direction of the channel being closed while removing the other channel from the tracked set. Repeated occurrences could leave active/passive tracking inconsistent and affect subsequent connection decisions.
The fix uses channel-instance identity for pool membership and removal. The TCP port-reuse capability is a prerequisite for the address collision; ordinary inbound and outbound connections normally use different remote ports.
This PR has been tested by:
Added lifecycle tests for same-address inbound and outbound channels in both close orders.
Tested duplicate close notifications, an unregistered channel, replacement notifications, and repeated connect/disconnect cycles.
Verified that active/passive counters and tracked channel instances remain consistent.
git diff --check passed.
Follow up
Keep the existing remote-address mapping in ChannelManager under review separately; this PR is limited to connection-pool bookkeeping.
Extra details
This change does not modify the wire protocol or require a protocol upgrade.
317787106
changed the title
fix(tcp): fix the bug of judge when if channel is already exist
fix(pool): track channels by instance when remote addresses collide
Sep 11, 2026
[SHOULD, java-tron follow-up] Please use channel identity (==) in getPeerConnection() and identity-based removal throughout PeerManager, including check().
Distinct channels sharing a remote address currently resolve to the same PeerConnection, which can skip handshake initialization, misassociate messages, and remove another connection's record. Please add tests covering both removal orders and duplicate disconnect callbacks.
[SHOULD, java-tron follow-up] Please use channel identity (==) in getPeerConnection() and identity-based removal throughout PeerManager, including check().
Distinct channels sharing a remote address currently resolve to the same PeerConnection, which can skip handshake initialization, misassociate messages, and remove another connection's record. Please add tests covering both removal orders and duplicate disconnect callbacks.
I will fix it in java-tron's PR also. If issues, i will comment it here.
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Channelinstance when different TCP channels have the same remoteInetSocketAddress.Channel.equals()during pool lifecycle bookkeeping.Why are these changes required?
Channel.equals()currently identifies a channel only by its remote socket address. If the remote host supports TCP source-port reuse and uses its listening port as the source port of an inbound connection, an inbound and an outbound channel can have the same remote address while remaining different TCP connections.The pool could then skip counting the second channel, but later decrement the counter according to the direction of the channel being closed while removing the other channel from the tracked set. Repeated occurrences could leave active/passive tracking inconsistent and affect subsequent connection decisions.
The fix uses channel-instance identity for pool membership and removal. The TCP port-reuse capability is a prerequisite for the address collision; ordinary inbound and outbound connections normally use different remote ports.
This PR has been tested by:
git diff --checkpassed.Follow up
Keep the existing remote-address mapping in
ChannelManagerunder review separately; this PR is limited to connection-pool bookkeeping.Extra details
This change does not modify the wire protocol or require a protocol upgrade.