improve: service URL parsing compatible with Go 1.26#1468
Conversation
e6359cf to
611b799
Compare
2bf5bb4 to
5df25c5
Compare
There was a problem hiding this comment.
Pull request overview
This PR refactors Pulsar service URL handling to stay compatible with stricter net/url.Parse behavior (Go 1.26), especially for multi-host service URLs, by centralizing parsing/validation in PulsarServiceURI / ServiceNameResolver and updating internal call sites accordingly.
Changes:
- Reworked
PulsarServiceURIparsing to parse a single-host URL viaurl.Parseand validate remaining hosts separately (avoiding strict-colon failures on multi-host URLs). - Refactored internal APIs to pass
ServiceNameResolver/service URL strings instead of*url.URL, updating RPC/lookup/HTTP client wiring and tests. - Updated build/test tooling and CI to default to Go 1.24 and add Go 1.26 with
GODEBUG=urlstrictcolons=1.
Reviewed changes
Copilot reviewed 14 out of 14 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
pulsar/internal/service_uri.go |
New parsing/validation approach; adds helpers for TLS/HTTP detection and primary hostname extraction. |
pulsar/internal/service_uri_test.go |
Updates/extends negative test cases to match stricter parsing expectations. |
pulsar/internal/service_name_resolver.go |
Resolver API now takes a service URL string and returns an error; removes stored *url.URL. |
pulsar/internal/service_name_resolver_test.go |
Adjusts resolver tests for new constructor/update signature. |
pulsar/internal/rpc_client.go |
NewRPCClient now takes a service URL string; lookup service creation routed through new parsing flow. |
pulsar/internal/rpc_client_test.go |
Updates RPC client tests to pass URL strings. |
pulsar/internal/lookup_service.go |
Lookup service constructors no longer take *url.URL; logging now uses resolver’s parsed URI. |
pulsar/internal/lookup_service_test.go |
Updates lookup service tests for new constructor signatures. |
pulsar/internal/http_client.go |
HTTP client constructor no longer takes *url.URL; logging derives from resolver. |
pulsar/client_impl.go |
Client creation now uses PulsarServiceURI for scheme/TLS decisions and passes URL string into internal RPC client. |
README.md |
Raises documented minimum Go version to 1.24 and updates example make test invocation. |
Makefile |
Updates default GO_VERSION to 1.24. |
Dockerfile |
Updates default GO_VERSION build arg to 1.24. |
.github/workflows/ci.yml |
CI matrix moves to Go 1.24 + 1.26 and enforces strict URL colon parsing via GODEBUG. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 14 out of 14 changed files in this pull request and generated 4 comments.
Comments suppressed due to low confidence (1)
pulsar/internal/rpc_client.go:116
- NewRPCClient() now initializes the base lookup service via c.LookupService(serviceURL), which caches the returned lookup service in urlLookupServiceMap. Close() then calls c.lookupService.Close() and also iterates urlLookupServiceMap closing each entry, causing the base lookup service to be closed twice. Consider creating the initial lookup service via c.newLookupService(serviceURL) (or otherwise ensure the base instance is not stored/closed twice).
lookupService, err := c.LookupService(serviceURL)
if err != nil {
return nil, fmt.Errorf("failed to create lookup service: %w", err)
}
c.lookupService = lookupService
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 15 out of 15 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Fixes #1466
Motivation
Go 1.26 introduces stricter URL parsing via
url.Parse, rejecting malformed URLs with multiple colons in the host, such ashttp://::1/orhttp://localhost:80:80/. Bracketed IPv6 addresses, e.g.http://[::1]/, remain valid. The old behavior can be restored withGODEBUG=urlstrictcolons=0.This change exposed redundancy and limitations in the Pulsar client's URL handling, especially for multi-host configurations and internal service resolution.
Modifications
ServiceNameResolveris now fully leveraged. Previously, both aurl.URLobject and aServiceNameResolver(which already contains the parsed URL and related info) were passed around, causing redundancy. After this refactor, only theServiceNameResolveris passed, which is sufficient for internal processing.PulsarServiceURIparsing is updated so multi-host service URLs can still be handled under Go 1.26 strict parsing. The parser splits host lists beforeurl.Parse, validates the remaining hosts separately, and adds stricter validation around malformed hosts and bracketed IPv6 usage.newClient,NewLookupService,NewHTTPLookupService) is streamlined. Some internal method signatures and interfaces have changed; these updates are confined to theinternalpackage and do not affect end users.IsHTTP()behavior, and resolver regressions.GODEBUG=urlstrictcolons=1.go mod download.