Skip to content

fix(rpc): restore plain host:port support for -diodeaddrs#248

Merged
dominicletz merged 1 commit intomasterfrom
247-diodeaddrs-hostport-stopped-working-after-a07e80f
Feb 26, 2026
Merged

fix(rpc): restore plain host:port support for -diodeaddrs#248
dominicletz merged 1 commit intomasterfrom
247-diodeaddrs-hostport-stopped-working-after-a07e80f

Conversation

@tuhalf
Copy link
Collaborator

@tuhalf tuhalf commented Feb 25, 2026

Fix regression introduced by a07e80f where plain host:port values could be normalized to :, causing single -diodeaddrs connections to fail (server=: in logs).

  • prefer SplitHostPort for plain host:port input
  • only URL-parse when a scheme exists and host/port are non-empty
  • apply the same guard in resolveRelayAddrFromClient
  • add regression tests for both plain and URL address formats
  • keep ci_test.sh on a single diodeaddr (override via DIODE_CI_DIODEADDR)

Fix regression introduced by a07e80f where plain `host:port` values
could be normalized to `:`, causing single `-diodeaddrs` connections
to fail (`server=:` in logs).

- prefer `SplitHostPort` for plain `host:port` input
- only URL-parse when a scheme exists and host/port are non-empty
- apply the same guard in `resolveRelayAddrFromClient`
- add regression tests for both plain and URL address formats
- keep `ci_test.sh` on a single diodeaddr (override via `DIODE_CI_DIODEADDR`)
@tuhalf tuhalf linked an issue Feb 25, 2026 that may be closed by this pull request
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @tuhalf, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request resolves a regression that caused single -diodeaddrs connections to fail due to incorrect normalization of host:port values. The changes refine the logic for parsing network addresses, ensuring that plain host:port strings are handled correctly and URL parsing is applied only when appropriate. This resolves connection issues and improves the robustness of address resolution within the RPC client manager by making the parsing more resilient to different input formats.

Highlights

  • Address Parsing Logic: Prioritized net.SplitHostPort for plain host:port inputs within normalizeHostPort to prevent incorrect normalization, addressing a regression.
  • URL Parsing Refinement: Ensured url.Parse is only used when a scheme is present and both host and port are non-empty, avoiding issues with malformed URLs.
  • Consistent Address Resolution: Applied the updated parsing guard within resolveRelayAddrFromClient for consistent and correct address resolution from client remote addresses.
  • Regression Testing: Introduced new regression tests to cover both plain host:port and URL address formats, verifying the fix and preventing future regressions.
  • CI Configuration: Maintained ci_test.sh to use a single diode address, with an override option for DIODE_CI_DIODEADDR for testing flexibility.
Changelog
  • rpc/client_manager.go
    • Modified normalizeHostPort to prioritize net.SplitHostPort for plain host:port strings and conditionally use url.Parse for URLs with schemes.
    • Updated resolveRelayAddrFromClient to apply the same refined address parsing logic for client remote addresses.
  • rpc/client_manager_normalize_test.go
    • Added a new test file containing regression tests for normalizeHostPort to verify correct handling of plain host:port, diode:// URLs, and HTTPS:// URLs.
Activity
  • No human activity has been recorded on this pull request yet.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request fixes a regression in address parsing by correctly handling plain host:port strings. The change prioritizes net.SplitHostPort over url.Parse, which resolves the issue. The logic is sound and is accompanied by a good set of regression tests. My review includes suggestions for improving code consistency and maintainability in both the implementation and the new tests.

Comment on lines 247 to 257
if host, port, err := net.SplitHostPort(remoteAddr.String()); err == nil {
return net.JoinHostPort(host, port), host
}
if strings.Contains(remoteAddr.String(), "://") {
if u, err := url.Parse(remoteAddr.String()); err == nil {
if host, port := strings.TrimSpace(u.Hostname()), strings.TrimSpace(u.Port()); host != "" && port != "" {
return net.JoinHostPort(host, port), host
}
}
}
return remoteAddr.String(), remoteAddr.String()
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

To improve readability and consistency, consider storing the result of remoteAddr.String() in a variable to avoid multiple calls. Additionally, the host should be normalized to lowercase for consistency with the normalizeHostPort function. This will make the code more robust and easier to maintain.

Suggested change
if host, port, err := net.SplitHostPort(remoteAddr.String()); err == nil {
return net.JoinHostPort(host, port), host
}
if strings.Contains(remoteAddr.String(), "://") {
if u, err := url.Parse(remoteAddr.String()); err == nil {
if host, port := strings.TrimSpace(u.Hostname()), strings.TrimSpace(u.Port()); host != "" && port != "" {
return net.JoinHostPort(host, port), host
}
}
}
return remoteAddr.String(), remoteAddr.String()
addrStr := remoteAddr.String()
if host, port, err := net.SplitHostPort(addrStr); err == nil {
host = strings.ToLower(strings.TrimSpace(host))
return net.JoinHostPort(host, port), host
}
if strings.Contains(addrStr, "://") {
if u, err := url.Parse(addrStr); err == nil {
if host, port := strings.ToLower(strings.TrimSpace(u.Hostname())), strings.TrimSpace(u.Port()); host != "" && port != "" {
return net.JoinHostPort(host, port), host
}
}
}
return addrStr, addrStr

Comment on lines +5 to +24
func TestNormalizeHostPortPlainHostPort(t *testing.T) {
got := normalizeHostPort("eu1.prenet.diode.io:41046")
if got != "eu1.prenet.diode.io:41046" {
t.Fatalf("expected plain host:port to remain unchanged, got %q", got)
}
}

func TestNormalizeHostPortFromDiodeURL(t *testing.T) {
got := normalizeHostPort("diode://0x937c492a77ae90de971986d003ffbc5f8bb2232c@eu1.prenet.diode.io:41046")
if got != "eu1.prenet.diode.io:41046" {
t.Fatalf("expected diode URL to normalize to host:port, got %q", got)
}
}

func TestNormalizeHostPortFromHTTPSURL(t *testing.T) {
got := normalizeHostPort("HTTPS://Example.COM:443")
if got != "example.com:443" {
t.Fatalf("expected HTTPS URL to normalize to lowercase host:port, got %q", got)
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

To improve the maintainability and readability of the tests, consider refactoring them into a single table-driven test. This is a common Go idiom that makes it easier to add new test cases in the future and reduces boilerplate code.

func TestNormalizeHostPort(t *testing.T) {
	testCases := []struct {
		name  string
		input string
		want  string
	}{
		{
			name:  "Plain host:port",
			input: "eu1.prenet.diode.io:41046",
			want:  "eu1.prenet.diode.io:41046",
		},
		{
			name:  "Diode URL",
			input: "diode://0x937c492a77ae90de971986d003ffbc5f8bb2232c@eu1.prenet.diode.io:41046",
			want:  "eu1.prenet.diode.io:41046",
		},
		{
			name:  "HTTPS URL with mixed case",
			input: "HTTPS://Example.COM:443",
			want:  "example.com:443",
		},
	}

	for _, tc := range testCases {
		t.Run(tc.name, func(t *testing.T) {
			got := normalizeHostPort(tc.input)
			if got != tc.want {
				t.Errorf("normalizeHostPort(%q) = %q, want %q", tc.input, got, tc.want)
			}
		})
	}
}

@dominicletz dominicletz merged commit 5563cb7 into master Feb 26, 2026
16 checks passed
@dominicletz dominicletz deleted the 247-diodeaddrs-hostport-stopped-working-after-a07e80f branch February 26, 2026 09:13
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.

-diodeaddrs host:port stopped working after a07e80f

2 participants