Skip to content

Handle an IPv6 peer address in the chaincode endpoint - #5634

Open
hmdsefi wants to merge 7 commits into
hyperledger:mainfrom
hmdsefi:fix/peer-chaincode-endpoint-ipv6
Open

hmdsefi wants to merge 7 commits into
hyperledger:mainfrom
hmdsefi:fix/peer-chaincode-endpoint-ipv6

Conversation

@hmdsefi

@hmdsefi hmdsefi commented Oct 21, 2026

Copy link
Copy Markdown
Contributor

Type of change

  • Bug fix

Description

When peer.chaincodeAddress is not set, computeChaincodeEndpoint in internal/peer/node/start.go builds the endpoint that chaincode connects to from the host of peer.address. It does the same when peer.chaincodeListenAddress has the host 0.0.0.0 or ::. When peer.chaincodeListenAddress is not set, createChaincodeServer also builds the listen address from that host. All three join host and port with fmt.Sprintf.

The host comes from net.SplitHostPort(peer.address), so for peer.address: "[2001:db8::1]:7051" it is 2001:db8::1, without brackets. The joined address is 2001:db8::1:7052, which is not a valid address, and the peer panics at startup:

Chaincode service host 2001:db8::1:7052 isn't a valid hostname: address 2001:db8::1:7052: too many colons in address

computeChaincodeEndpoint already treats :: like 0.0.0.0, so IPv6 is meant to work here. Setting peer.chaincodeAddress explicitly avoids the problem.

This change uses net.JoinHostPort in those three places. It adds the brackets for IPv6 hosts and gives the same result as before for IPv4 addresses and host names.

Additional details

Tests:

  • New TestComputeChaincodeEndpoint cases for an IPv6 peer address, with peer.chaincodeListenAddress unset, set to [::]:8052, and set to another IPv6 address. Without the fix, the first two fail with expected: "[2001:db8::1]:7052", actual: "2001:db8::1:7052" (and the same for port 8052).
  • TestCreateChaincodeServerIPv6PeerAddress calls createChaincodeServer with the peer host ::1 and no chaincode addresses set, and checks the endpoint and the listen address. Without the fix, it panics with the error above. With only the computeChaincodeEndpoint part of the fix, it fails with listen tcp: address ::1:7052: too many colons in address. It is skipped when the IPv6 loopback address can't be used.

Ran:

  • go test -race ./internal/peer/node/... passes.
  • golangci-lint reports no issues.

Related issues

Fixes #5633.

When peer.chaincodeAddress is not set, the peer builds the chaincode
endpoint, and the chaincode listen address if that is not set either,
from the host of peer.address and a port with "%s:%s". For an IPv6
host such as 2001:db8::1 this gives 2001:db8::1:7052, which is not a
valid address. createChaincodeServer then panics with "too many colons
in address" and the peer does not start.

Use net.JoinHostPort, which adds the brackets for IPv6 hosts.

Signed-off-by: Hamed Yousefi <hdyousefi@gmail.com>
@hmdsefi
hmdsefi requested a review from a team as a code owner October 21, 2026 11:52
@mergify

mergify Bot commented Nov 13, 2026

Copy link
Copy Markdown

Tick the box to add this pull request to the merge queue (same as @mergifyio queue). If it does not match the queue conditions yet, it enters the queue once it does.

  • Queue this pull request

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.

Peer panics at startup with an IPv6 peer.address

1 participant