aboutsummaryrefslogtreecommitdiffhomepage
path: root/tools/run_tests/python_utils
diff options
context:
space:
mode:
authorGravatar Craig Tiller <ctiller@google.com>2017-04-24 20:55:43 +0000
committerGravatar Craig Tiller <ctiller@google.com>2017-04-24 20:55:43 +0000
commitec4952426976c60e33fb279aa36a1cd1f89bd938 (patch)
tree03a155d360a29481cfa04dd0c48da56e28dca665 /tools/run_tests/python_utils
parentea525ebd3949f89923f30da22471495e9e066326 (diff)
Add a mutex around allocate_port
Diffstat (limited to 'tools/run_tests/python_utils')
-rwxr-xr-xtools/run_tests/python_utils/port_server.py8
1 files changed, 7 insertions, 1 deletions
diff --git a/tools/run_tests/python_utils/port_server.py b/tools/run_tests/python_utils/port_server.py
index 67ae471582..522cbed9e1 100755
--- a/tools/run_tests/python_utils/port_server.py
+++ b/tools/run_tests/python_utils/port_server.py
@@ -46,7 +46,7 @@ import threading
# increment this number whenever making a change to ensure that
# the changes are picked up by running CI servers
# note that all changes must be backwards compatible
-_MY_VERSION = 10
+_MY_VERSION = 11
if len(sys.argv) == 2 and sys.argv[1] == 'dump_version':
@@ -70,6 +70,7 @@ print('port server running on port %d' % args.port)
pool = []
in_use = {}
+mu = threading.Lock()
def refill_pool(max_timeout, req):
@@ -97,16 +98,21 @@ def refill_pool(max_timeout, req):
def allocate_port(req):
global pool
global in_use
+ global mu
+ mu.acquire()
max_timeout = 600
while not pool:
refill_pool(max_timeout, req)
if not pool:
req.log_message("failed to find ports: retrying soon")
+ mu.release()
time.sleep(1)
+ mu.acquire()
max_timeout /= 2
port = pool[0]
pool = pool[1:]
in_use[port] = time.time()
+ mu.release()
return port