15954: More careful about finding available ports.
authorTom Clegg <tom@tomclegg.ca>
Wed, 26 Feb 2020 07:01:33 +0000 (02:01 -0500)
committerTom Clegg <tom@tomclegg.ca>
Wed, 26 Feb 2020 07:01:33 +0000 (02:01 -0500)
Arvados-DCO-1.1-Signed-off-by: Tom Clegg <tom@tomclegg.ca>

lib/boot/supervisor.go

index 59e1ae352e6110dfebc01718ee08ee4e399f1b24..784428b352fa55270b880ce6138b70e81a208942 100644 (file)
@@ -503,7 +503,7 @@ func (super *Supervisor) autofillConfig(cfg *arvados.Config, log logrus.FieldLog
        usedPort := map[string]bool{}
        nextPort := func() string {
                for {
-                       port, err := availablePort(super.ListenHost + ":0")
+                       port, err := availablePort(super.ListenHost)
                        if err != nil {
                                panic(err)
                        }
@@ -523,7 +523,7 @@ func (super *Supervisor) autofillConfig(cfg *arvados.Config, log logrus.FieldLog
                        h = super.ListenHost
                }
                if p == "0" {
-                       p, err = availablePort(":0")
+                       p, err = availablePort(h)
                        if err != nil {
                                return err
                        }
@@ -660,8 +660,8 @@ func externalPort(svc arvados.Service) (string, error) {
        }
 }
 
-func availablePort(addr string) (string, error) {
-       ln, err := net.Listen("tcp", addr)
+func availablePort(host string) (string, error) {
+       ln, err := net.Listen("tcp", net.JoinHostPort(host, "0"))
        if err != nil {
                return "", err
        }