]> granicus.if.org Git - python/commitdiff
Fix test.test_support.bind_port() to not cause an error when Python was
authorGregory P. Smith <greg@krypto.org>
Mon, 25 Nov 2013 03:42:15 +0000 (19:42 -0800)
committerGregory P. Smith <greg@krypto.org>
Mon, 25 Nov 2013 03:42:15 +0000 (19:42 -0800)
compiled on a system with SO_REUSEPORT defined in the headers but run on
a system with an OS kernel that does not support that new socket option.

Lib/test/test_support.py
Misc/NEWS

index e3dd7129e6ab6d656d08d0ca4664c691c3784c9c..d82edb01e564d357f4f19435283a8f649db94703 100644 (file)
@@ -409,9 +409,15 @@ def bind_port(sock, host=HOST):
                 raise TestFailed("tests should never set the SO_REUSEADDR "   \
                                  "socket option on TCP/IP sockets!")
         if hasattr(socket, 'SO_REUSEPORT'):
-            if sock.getsockopt(socket.SOL_SOCKET, socket.SO_REUSEPORT) == 1:
-                raise TestFailed("tests should never set the SO_REUSEPORT "   \
-                                 "socket option on TCP/IP sockets!")
+            try:
+                if sock.getsockopt(socket.SOL_SOCKET, socket.SO_REUSEPORT) == 1:
+                    raise TestFailed("tests should never set the SO_REUSEPORT "   \
+                                     "socket option on TCP/IP sockets!")
+            except EnvironmentError:
+                # Python's socket module was compiled using modern headers
+                # thus defining SO_REUSEPORT but this process is running
+                # under an older kernel that does not support SO_REUSEPORT.
+                pass
         if hasattr(socket, 'SO_EXCLUSIVEADDRUSE'):
             sock.setsockopt(socket.SOL_SOCKET, socket.SO_EXCLUSIVEADDRUSE, 1)
 
index 4863da8bcab1513924fac3e43611e9a80628ef3f..f845ae36b95b7e354a2550d138830798ee1a0679 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -12,6 +12,10 @@ Core and Builtins
 Library
 -------
 
+- Fix test.test_support.bind_port() to not cause an error when Python was
+  compiled on a system with SO_REUSEPORT defined in the headers but run on
+  a system with an OS kernel that does not support that new socket option.
+
 - Issue #19633: Fixed writing not compressed 16- and 32-bit wave files on
   big-endian platforms.