Skip to content

fix(pool): track channels by instance when remote addresses collide - #154

Open
317787106 wants to merge 1 commit into
tronprotocol:release-v2.3.0from
317787106:fix/same_inet_socket_address
Open

317787106 wants to merge 1 commit into
tronprotocol:release-v2.3.0from
317787106:fix/same_inet_socket_address

Conversation

@317787106

@317787106 317787106 commented Sep 11, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

  • 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 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
@3for

3for commented Sep 14, 2026

Copy link
Copy Markdown

[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.

@317787106

Copy link
Copy Markdown
Contributor Author

[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.

@317787106
317787106 changed the base branch from main to release-v2.3.0 September 15, 2026 03:58

@3for 3for left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants