Devserver should fall back to IPv4 when IPv6 is not configured
socket.AF_INET6 is defined whether python is configured with IPv6
enabled or not. Thus creating a new IPv6 socket would not throw an
exception, but using the socket later would. This change uses
socket.has_ipv6 to determine whether IPv6 is available.
BUG=chromium:318443
TEST=devserver.py startup on a DUT
Change-Id: I665faafd8bc914c26d7c2a68ff8a232d2e48618d
Reviewed-on: https://chromium-review.googlesource.com/176572
Reviewed-by: Chris Sosa <[email protected]>
Commit-Queue: Yu-Ju Hong <[email protected]>
Tested-by: Yu-Ju Hong <[email protected]>
diff --git a/devserver.py b/devserver.py
index 9094264..5a61cea 100755
--- a/devserver.py
+++ b/devserver.py
@@ -145,13 +145,9 @@
def _GetConfig(options):
"""Returns the configuration for the devserver."""
- # On a system with IPv6 not compiled into the kernel,
- # AF_INET6 sockets will return a socket.error exception.
- # On such systems, fall-back to IPv4.
socket_host = '::'
- try:
- socket.socket(socket.AF_INET6, socket.SOCK_STREAM)
- except socket.error:
+ # Fall back to IPv4 when python is not configured with IPv6.
+ if not socket.has_ipv6:
socket_host = '0.0.0.0'
base_config = { 'global':