From 6ffa19d2cecf49f4b785a5ff454a6eedb2b55de9 Mon Sep 17 00:00:00 2001 From: Hein Meling Date: Tue, 13 Oct 2026 09:07:36 +0200 Subject: [PATCH] servers: wrap bufconn fake ports within the valid range The bufconn registry's process-wide counter never reset, so a long -count run passed port 65535 and every later test failed with an invalid address. Wrap the port; addresses only need to be distinct among the listeners alive at once. Closes: #366 --- internal/testutils/servers/bufconn.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/internal/testutils/servers/bufconn.go b/internal/testutils/servers/bufconn.go index 281c1aa7..c9b797a5 100644 --- a/internal/testutils/servers/bufconn.go +++ b/internal/testutils/servers/bufconn.go @@ -34,9 +34,11 @@ var globalBufconnRegistry = &bufconnRegistry{ dialers: make(map[testing.TB]bufconnDialer), } -// nextAddress generates a unique fake address for a bufconn listener. +// nextAddress generates a fake address for a bufconn listener. The port wraps +// around within the valid range, so a long -count run does not overflow it; +// addresses only need to be distinct among the listeners alive at once. func (r *bufconnRegistry) nextAddress() string { - port := r.portCounter.Add(1) + port := r.portCounter.Add(1) % (65536 - 10000) return fmt.Sprintf("127.0.0.1:%d", 10000+port) }