Skip to content

Use net.JoinHostPort for host:port formatting to handle IPv6 #22359

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 4, 2025

Conversation

krutibaraiya
Copy link
Contributor

@krutibaraiya krutibaraiya commented May 26, 2025

Description

This change replaces all uses of fmt.Sprintf("%s:%d", host, port) with net.JoinHostPort(host, strconv.Itoa(port)) to ensure correct formatting of host:port strings. Using net.JoinHostPort is safer and more robust, especially for IPv6 addresses, which require square brackets to be parsed correctly. This refactor improves reliability, ensures compatibility across both IPv4 and IPv6 and prevents bugs related to improperly formatted addresses

Testing & Reproduction steps

PR Checklist

  • updated test coverage
  • external facing docs updated
  • appropriate backport labels added
  • not a security concern

@krutibaraiya krutibaraiya added backport/1.21 Changes are backported to 1.21 backport/ent/1.21 changes are backported to 1.21 ent labels May 26, 2025
@github-actions github-actions bot added theme/cli Flags and documentation for the CLI interface theme/connect Anything related to Consul Connect, Service Mesh, Side Car Proxies theme/envoy/xds Related to Envoy support labels May 26, 2025
@krutibaraiya krutibaraiya changed the title refactor: use net.JoinHostPort for address formatting Refactor address formatting to use net.JoinHostPort for IPv6 safety and correctness May 26, 2025
@krutibaraiya krutibaraiya marked this pull request as ready for review May 26, 2025 10:49
@krutibaraiya krutibaraiya requested a review from a team as a code owner May 26, 2025 10:49
@krutibaraiya krutibaraiya requested a review from sreeram77 May 26, 2025 12:06
Copy link

hashicorp-cla-app bot commented May 26, 2025

CLA assistant check
All committers have signed the CLA.

@krutibaraiya krutibaraiya changed the title Refactor address formatting to use net.JoinHostPort for IPv6 safety and correctness Use net.JoinHostPort for host:port formatting to handle IPv6 May 26, 2025
Copy link
Contributor

@srahul3 srahul3 left a comment

Choose a reason for hiding this comment

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

✅ LGTM

krutibaraiya and others added 4 commits June 3, 2025 16:32
This change improves reliability and correctness when handling IPv6 addresses
Co-authored-by: Sreeram Narayanan <[email protected]>
Co-authored-by: Sreeram Narayanan <[email protected]>
@krutibaraiya krutibaraiya force-pushed the kruti/fix-ipv6-address-handling branch from 19a3511 to 76190c3 Compare June 3, 2025 11:02
@krutibaraiya krutibaraiya merged commit 0ff1775 into main Jun 4, 2025
94 checks passed
@krutibaraiya krutibaraiya deleted the kruti/fix-ipv6-address-handling branch June 4, 2025 05:45
@hc-github-team-consul-core
Copy link
Collaborator

📣 Hi @krutibaraiya! a backport is missing for this PR [22359] for versions [1.21] please perform the backport manually and add the following snippet to your backport PR description:

<details>
	<summary> Overview of commits </summary>
		- <<backport commit 1>>
		- <<backport commit 2>>
		...
</details>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport/ent/1.21 changes are backported to 1.21 ent backport/1.21 Changes are backported to 1.21 theme/cli Flags and documentation for the CLI interface theme/connect Anything related to Consul Connect, Service Mesh, Side Car Proxies theme/envoy/xds Related to Envoy support
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants