Skip to content

Commit 36e13de

Browse files
authored
grpclb: replace net.IP with netip.Addr (#8918)
Contributes to #8884 This PR replaces deprecated `net.IP` usage with the modern `netip.Addr` API in two packages: - **grpclb**: Replace `net.IP(s.IpAddress).String()` with `netip.AddrFromSlice()` in `processServerList`, adding proper error handling for invalid IP addresses instead of silently producing `"?"` from `net.IP.String()`. Note: `x509.Certificate.IPAddresses` fields in test files (`internal/credentials/xds/handshake_info_test.go`, `security/advancedtls/crl_test.go`) are typed as `[]net.IP` by the standard library, so those cannot be migrated. The xds/server and xds/xdsclient packages are being addressed in #8909. RELEASE NOTES: N/A
1 parent 7f78342 commit 36e13de

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

balancer/grpclb/grpclb_remote_balancer.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"fmt"
2424
"io"
2525
"net"
26+
"net/netip"
2627
"sync"
2728
"time"
2829

@@ -82,7 +83,12 @@ func (lb *lbBalancer) processServerList(l *lbpb.ServerList) {
8283
}
8384

8485
md := metadata.Pairs(lbTokenKey, s.LoadBalanceToken)
85-
ipStr := net.IP(s.IpAddress).String()
86+
var ipStr string
87+
if ip, ok := netip.AddrFromSlice(s.IpAddress); ok {
88+
ipStr = ip.String()
89+
} else {
90+
ipStr = fmt.Sprintf("? %x", s.IpAddress)
91+
}
8692
addr := imetadata.Set(resolver.Address{Addr: net.JoinHostPort(ipStr, fmt.Sprintf("%d", s.Port))}, md)
8793
if lb.logger.V(2) {
8894
lb.logger.Infof("Server list entry:|%d|, ipStr:|%s|, port:|%d|, load balancer token:|%v|", i, ipStr, s.Port, s.LoadBalanceToken)

0 commit comments

Comments
 (0)