From b9adb28e90f838ceda6a7dd2118c81d3a3fd3dad Mon Sep 17 00:00:00 2001 From: paspo Date: Fri, 3 Jul 2026 18:18:48 +0200 Subject: [PATCH] support use of random free port for healthcheck --- main.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index 9da12a1..47e0e0e 100644 --- a/main.go +++ b/main.go @@ -190,7 +190,15 @@ func main() { }) clients := startSending(*maxClients, *bannerMaxLength, records) - // Start the healthcheck listener. + if *healthcheckPort == "0" || *healthcheckPort == "" { + l, err := net.Listen("tcp", *healthcheckHost+":0") + if err != nil { + glog.Fatalf("Failed to pick a free healthcheck port: %v", err) + } + actualPort := l.Addr().(*net.TCPAddr).Port + *healthcheckPort = strconv.Itoa(actualPort) + l.Close() + } health.StartListener(*healthcheckHost, *healthcheckPort) interval := time.Duration(*intervalMs) * time.Millisecond