]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-38907: Suppress any exception when attempting to set V6ONLY. (GH-17864) (GH-17865)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Mon, 6 Jan 2020 13:28:27 +0000 (05:28 -0800)
committerJason R. Coombs <jaraco@jaraco.com>
Mon, 6 Jan 2020 13:28:27 +0000 (08:28 -0500)
Fixes error attempting to bind to IPv4 address.
(cherry picked from commit 7cdc31a14c824000cbe8b487900c9826a33f6940)

Co-authored-by: Jason R. Coombs <jaraco@jaraco.com>
Co-authored-by: Jason R. Coombs <jaraco@jaraco.com>
Lib/http/server.py

index 0fe44bdaa73feb48469aa18700c54c8c874055a8..38f7accad7a346499a7de40c481a8fe73c81ca4c 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
@@ -1284,7 +1285,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(