From d82634d606583d7e2a55f57be70882a77aba5171 Mon Sep 17 00:00:00 2001 From: "Gregory P. Smith" Date: Sun, 24 Nov 2013 19:42:15 -0800 Subject: [PATCH] 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. --- Lib/test/test_support.py | 12 +++++++++--- Misc/NEWS | 4 ++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/Lib/test/test_support.py b/Lib/test/test_support.py index e3dd7129e6..d82edb01e5 100644 --- a/Lib/test/test_support.py +++ b/Lib/test/test_support.py @@ -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) diff --git a/Misc/NEWS b/Misc/NEWS index 4863da8bca..f845ae36b9 100644 --- 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. -- 2.50.1