From 0564d0a2cf00d4b499a5b54a4e48675f795a27b0 Mon Sep 17 00:00:00 2001 From: Wade Simmons Date: Mon, 8 Jan 2024 13:49:44 -0500 Subject: [PATCH] when listen.port is zero, fix multiple routines (#1057) This used to work correctly because when the multiple routines work was first added in #382, but an important part to discover the listen port before opening the other listeners on the same socket was lost in this PR: #653. This change should fix the regression and allow multiple routines to work correctly when listen.port is set to `0`. Thanks to @rawdigits for tracking down and discovering this regression. --- main.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/main.go b/main.go index fd3b687..8c94e80 100644 --- a/main.go +++ b/main.go @@ -170,6 +170,16 @@ func Main(c *config.C, configTest bool, buildVersion string, logger *logrus.Logg } udpServer.ReloadConfig(c) udpConns[i] = udpServer + + // If port is dynamic, discover it before the next pass through the for loop + // This way all routines will use the same port correctly + if port == 0 { + uPort, err := udpServer.LocalAddr() + if err != nil { + return nil, util.NewContextualError("Failed to get listening port", nil, err) + } + port = int(uPort.Port) + } } }