Skip to content

Commit 33cb4a6

Browse files
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 7cdc31a) Co-authored-by: Jason R. Coombs <[email protected]> Co-authored-by: Jason R. Coombs <[email protected]>
1 parent 5ed9d60 commit 33cb4a6

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
@@ -1284,7 +1285,10 @@ def test(HandlerClass=BaseHTTPRequestHandler,
12841285
# ensure dual-stack is not disabled; ref #38907
12851286
class DualStackServer(ThreadingHTTPServer):
12861287
def server_bind(self):
1287-
self.socket.setsockopt(socket.IPPROTO_IPV6, socket.IPV6_V6ONLY, 0)
1288+
# suppress exception when protocol is IPv4
1289+
with contextlib.suppress(Exception):
1290+
self.socket.setsockopt(
1291+
socket.IPPROTO_IPV6, socket.IPV6_V6ONLY, 0)
12881292
return super().server_bind()
12891293

12901294
test(

0 commit comments

Comments
 (0)