Skip to content

Commit 7cdc31a

Browse files
authored
bpo-38907: Suppress any exception when attempting to set V6ONLY. (GH-17864)
Fixes error attempting to bind to IPv4 address.
1 parent 5136e72 commit 7cdc31a

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

Lib/http/server.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@
103103
import sys
104104
import time
105105
import urllib.parse
106+
import contextlib
106107
from functools import partial
107108

108109
from http import HTTPStatus
@@ -1286,7 +1287,10 @@ def test(HandlerClass=BaseHTTPRequestHandler,
12861287
# ensure dual-stack is not disabled; ref #38907
12871288
class DualStackServer(ThreadingHTTPServer):
12881289
def server_bind(self):
1289-
self.socket.setsockopt(socket.IPPROTO_IPV6, socket.IPV6_V6ONLY, 0)
1290+
# suppress exception when protocol is IPv4
1291+
with contextlib.suppress(Exception):
1292+
self.socket.setsockopt(
1293+
socket.IPPROTO_IPV6, socket.IPV6_V6ONLY, 0)
12901294
return super().server_bind()
12911295

12921296
test(

0 commit comments

Comments
 (0)