]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-38907: Suppress any exception when attempting to set V6ONLY. (GH-17864)
authorJason R. Coombs <jaraco@jaraco.com>
Mon, 6 Jan 2020 12:59:36 +0000 (07:59 -0500)
committerGitHub <noreply@github.com>
Mon, 6 Jan 2020 12:59:36 +0000 (07:59 -0500)
Fixes error attempting to bind to IPv4 address.

Lib/http/server.py

index b9a2717681f536d0ad8cd6f18b61a71749ceb7db..c6e5ed6ea0e0023075c25a7461ad4fb6fde1a16a 100644 (file)
@@ -103,6 +103,7 @@ import socketserver
 import sys
 import time
 import urllib.parse
+import contextlib
 from functools import partial
 
 from http import HTTPStatus
@@ -1286,7 +1287,10 @@ if __name__ == '__main__':
     # ensure dual-stack is not disabled; ref #38907
     class DualStackServer(ThreadingHTTPServer):
         def server_bind(self):
-            self.socket.setsockopt(socket.IPPROTO_IPV6, socket.IPV6_V6ONLY, 0)
+            # suppress exception when protocol is IPv4
+            with contextlib.suppress(Exception):
+                self.socket.setsockopt(
+                    socket.IPPROTO_IPV6, socket.IPV6_V6ONLY, 0)
             return super().server_bind()
 
     test(