[ARVADOS] updated: 7939a927a2b0584210d5e8b2fe73f7625858d6bd

git at public.curoverse.com git at public.curoverse.com
Fri Feb 6 13:06:21 EST 2015


Summary of changes:
 sdk/python/tests/run_test_server.py | 27 +++++++++++----------------
 1 file changed, 11 insertions(+), 16 deletions(-)

       via  7939a927a2b0584210d5e8b2fe73f7625858d6bd (commit)
      from  a94e15cab04a19dcbb02f2e95335e337c8e55036 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.


commit 7939a927a2b0584210d5e8b2fe73f7625858d6bd
Author: Tom Clegg <tom at curoverse.com>
Date:   Fri Feb 6 12:46:57 2015 -0500

    3021: Use bind(0.0.0.0, 0) instead of grep /proc/net/tcp to find a port number.

diff --git a/sdk/python/tests/run_test_server.py b/sdk/python/tests/run_test_server.py
index dce1e73..5fee9eb 100644
--- a/sdk/python/tests/run_test_server.py
+++ b/sdk/python/tests/run_test_server.py
@@ -9,6 +9,7 @@ import random
 import re
 import shutil
 import signal
+import socket
 import subprocess
 import string
 import sys
@@ -94,28 +95,22 @@ def kill_server_pid(pidfile, wait=10, passenger_root=False):
         pass
 
 def find_available_port():
-    """Return a port number that is not in use right now.
+    """Return an IPv4 port number that is not in use right now.
+
+    We assume whoever needs to use the returned port is able to reuse
+    a recently used port without waiting for TIME_WAIT (see
+    SO_REUSEADDR / SO_REUSEPORT).
 
     Some opportunity for races here, but it's better than choosing
     something at random and not checking at all. If all of our servers
     (hey Passenger) knew that listening on port 0 was a thing, the OS
     would take care of the races, and this wouldn't be needed at all.
     """
-    port = None
-    while port is None:
-        port = random.randint(20000, 40000)
-        port_hex = ':%04x ' % port
-        try:
-            with open('/proc/net/tcp', 'r') as f:
-                for line in f:
-                    if 0 <= string.find(line, port_hex):
-                        port = None
-                        break
-        except OSError:
-            # This isn't going so well. Just use the random port.
-            pass
-        except IOError:
-            pass
+
+    sock = socket.socket()
+    sock.bind(('0.0.0.0', 0))
+    port = sock.getsockname()[1]
+    sock.close()
     return port
 
 def run(leave_running_atexit=False):

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


hooks/post-receive
-- 




More information about the arvados-commits mailing list