From 262e341c9a07a5b0fba764c17722f7fe5f73b21f Mon Sep 17 00:00:00 2001 From: Gesh Markov Date: Fri, 3 Nov 2023 11:51:22 +0000 Subject: [PATCH] Prefer IPv4 over IPv6 for dual-stack sockets. --- _pydevd_bundle/pydevd_comm.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/_pydevd_bundle/pydevd_comm.py b/_pydevd_bundle/pydevd_comm.py index 4ff7342d..c3b5ce89 100644 --- a/_pydevd_bundle/pydevd_comm.py +++ b/_pydevd_bundle/pydevd_comm.py @@ -466,10 +466,13 @@ def start_client(host, port): address_family = AF_INET for res in socket_module.getaddrinfo(host, port, 0, SOCK_STREAM): - if res[0] == AF_INET6: - # Prefer IPv6 addresses. + if res[0] == AF_INET: address_family = res[0] + # Prefer IPv4 addresses for backward compat. break + if res[0] == AF_INET6: + # Don't break after this - if the socket is dual-stack prefer IPv4. + address_family = res[0] s = socket(address_family, SOCK_STREAM)