From: Tom Clegg Date: Thu, 14 Jul 2022 04:23:18 +0000 (-0400) Subject: 16552: Avoid port collision due to port assignment races in tests. X-Git-Tag: 2.5.0~116^2~3 X-Git-Url: https://git.arvados.org/arvados.git/commitdiff_plain/e12c1fed6336048d6ab854bbfab95eccf7c1b372 16552: Avoid port collision due to port assignment races in tests. Arvados-DCO-1.1-Signed-off-by: Tom Clegg --- diff --git a/lib/boot/nginx.go b/lib/boot/nginx.go index 8a29823a12..b391c4dc8c 100644 --- a/lib/boot/nginx.go +++ b/lib/boot/nginx.go @@ -32,8 +32,19 @@ func (runNginx) Run(ctx context.Context, fail func(error), super *Supervisor) er if err != nil { return err } + extListenHost := "0.0.0.0" + if super.ClusterType == "test" { + // Our dynamic port number assignment strategy (choose + // an available port, write it in a config file, and + // have another process/goroutine bind to it) is prone + // to races when used by concurrent supervisors. In + // test mode we don't accept remote connections, so we + // can avoid collisions by using the per-cluster + // loopback address instead of 0.0.0.0. + extListenHost = super.ListenHost + } vars := map[string]string{ - "LISTENHOST": "0.0.0.0", + "LISTENHOST": extListenHost, "UPSTREAMHOST": super.ListenHost, "SSLCERT": filepath.Join(super.tempdir, "server.crt"), "SSLKEY": filepath.Join(super.tempdir, "server.key"),