Skip to content

Commit

Permalink
bpo-38907: Suppress any exception when attempting to set V6ONLY. (GH-…
Browse files Browse the repository at this point in the history
…17864)

Fixes error attempting to bind to IPv4 address.
  • Loading branch information
jaraco authored Jan 6, 2020
1 parent 5136e72 commit 7cdc31a
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion Lib/http/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@
import sys
import time
import urllib.parse
import contextlib
from functools import partial

from http import HTTPStatus
Expand Down Expand Up @@ -1286,7 +1287,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(
Expand Down

0 comments on commit 7cdc31a

Please sign in to comment.