[Python-checkins] bpo-38907: Suppress any exception when attempting to set V6ONLY. (GH-17864) (GH-17865)

Jason R. Coombs webhook-mailer at python.org
Mon Jan 6 08:28:31 EST 2020


https://github.com/python/cpython/commit/33cb4a62bf6848093b7a05c9794582d204798b1b
commit: 33cb4a62bf6848093b7a05c9794582d204798b1b
branch: 3.8
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: Jason R. Coombs <jaraco at jaraco.com>
date: 2020-01-06T08:28:27-05:00
summary:

bpo-38907: Suppress any exception when attempting to set V6ONLY. (GH-17864) (GH-17865)

Fixes error attempting to bind to IPv4 address.
(cherry picked from commit 7cdc31a14c824000cbe8b487900c9826a33f6940)

Co-authored-by: Jason R. Coombs <jaraco at jaraco.com>

Co-authored-by: Jason R. Coombs <jaraco at jaraco.com>

files:
M Lib/http/server.py

diff --git a/Lib/http/server.py b/Lib/http/server.py
index 0fe44bdaa73fe..38f7accad7a34 100644
--- a/Lib/http/server.py
+++ b/Lib/http/server.py
@@ -103,6 +103,7 @@
 import sys
 import time
 import urllib.parse
+import contextlib
 from functools import partial
 
 from http import HTTPStatus
@@ -1284,7 +1285,10 @@ def test(HandlerClass=BaseHTTPRequestHandler,
     # 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(



More information about the Python-checkins mailing list