summaryrefslogtreecommitdiffstats
path: root/Lib/http
diff options
context:
space:
mode:
authorJason R. Coombs <jaraco@jaraco.com>2020-01-06 12:59:36 (GMT)
committerGitHub <noreply@github.com>2020-01-06 12:59:36 (GMT)
commit7cdc31a14c824000cbe8b487900c9826a33f6940 (patch)
treed56ffbecc69625fe13a718bdba4778f4f4ad892a /Lib/http
parent5136e721d7d9eae62ffad17328566b2315e42c00 (diff)
downloadcpython-7cdc31a14c824000cbe8b487900c9826a33f6940.zip
cpython-7cdc31a14c824000cbe8b487900c9826a33f6940.tar.gz
cpython-7cdc31a14c824000cbe8b487900c9826a33f6940.tar.bz2
bpo-38907: Suppress any exception when attempting to set V6ONLY. (GH-17864)
Fixes error attempting to bind to IPv4 address.
Diffstat (limited to 'Lib/http')
-rw-r--r--Lib/http/server.py6
1 files changed, 5 insertions, 1 deletions
diff --git a/Lib/http/server.py b/Lib/http/server.py
index b9a2717..c6e5ed6 100644
--- a/Lib/http/server.py
+++ b/Lib/http/server.py
@@ -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(