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

Lib/test/support/__init__.py
Misc/NEWS

index dbd784673731e76c03b19e40063e3dab42763bc1..233b13adcd9155bfac294acb6f96d985e34bf25c 100644 (file)
@@ -570,9 +570,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 OSError:
+                # 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 c30c6bc4def70ad082ac13139d0b023ec1d6ced5..1ea0e47cee80437d8a351f0f864a523d0dfbbd38 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -13,6 +13,10 @@ Core and Builtins
 Library
 -------
 
+- Fix 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 reasonably new socket option.
+
 - Fix compilation error under gcc of the ctypes module bundled libffi for arm.
 
 - Issue #19523: Closed FileHandler leak which occurred when delay was set.