[ARVADOS] created: 2.1.0-190-g35240500d

Git user git at public.arvados.org
Mon Dec 7 18:44:19 UTC 2020


        at  35240500d075e5a2474caa8ab550c40ff60f978f (commit)


commit 35240500d075e5a2474caa8ab550c40ff60f978f
Author: Tom Clegg <tom at tomclegg.ca>
Date:   Mon Dec 7 13:43:23 2020 -0500

    17199: Avoid returning same port twice from find_available_port().
    
    Arvados-DCO-1.1-Signed-off-by: Tom Clegg <tom at tomclegg.ca>

diff --git a/sdk/python/tests/run_test_server.py b/sdk/python/tests/run_test_server.py
index 0cb4151ac..c79aa4e94 100644
--- a/sdk/python/tests/run_test_server.py
+++ b/sdk/python/tests/run_test_server.py
@@ -73,6 +73,7 @@ if not os.path.exists(TEST_TMPDIR):
 my_api_host = None
 _cached_config = {}
 _cached_db_config = {}
+_already_used_port = {}
 
 def find_server_pid(PID_PATH, wait=10):
     now = time.time()
@@ -181,11 +182,15 @@ def find_available_port():
     would take care of the races, and this wouldn't be needed at all.
     """
 
-    sock = socket.socket()
-    sock.bind(('0.0.0.0', 0))
-    port = sock.getsockname()[1]
-    sock.close()
-    return port
+    global _already_used_port
+    while True:
+        sock = socket.socket()
+        sock.bind(('0.0.0.0', 0))
+        port = sock.getsockname()[1]
+        sock.close()
+        if port not in _already_used_port:
+            _already_used_port[port] = True
+            return port
 
 def _wait_until_port_listens(port, timeout=10, warn=True):
     """Wait for a process to start listening on the given port.

-----------------------------------------------------------------------


hooks/post-receive
-- 




More information about the arvados-commits mailing list