Sdm0 commited on
Commit
391275c
·
verified ·
1 Parent(s): 8862e23

Deploy 843ca13b

Browse files
Files changed (1) hide show
  1. backend/api.py +9 -7
backend/api.py CHANGED
@@ -43,12 +43,14 @@ def _temporary_network_probe():
43
  host = "api.cloudflare.com"
44
  try:
45
  addresses = socket.getaddrinfo(host, 443, type=socket.SOCK_STREAM)
46
- candidates = {}
 
47
  for family, kind, proto, _, address in addresses:
48
- if family in (socket.AF_INET, socket.AF_INET6):
49
- candidates.setdefault(family, (kind, proto, address))
50
- logger.warning("Network diagnostic: IPv4=%s IPv6=%s", socket.AF_INET in candidates, socket.AF_INET6 in candidates)
51
- for family, (kind, proto, address) in candidates.items():
 
52
  for attempt in range(2):
53
  start = time.monotonic()
54
  try:
@@ -56,9 +58,9 @@ def _temporary_network_probe():
56
  sock.settimeout(12)
57
  sock.connect(address)
58
  with ssl.create_default_context().wrap_socket(sock, server_hostname=host):
59
- logger.warning("Network diagnostic: family=%s attempt=%d TLS=ok duration=%.2fs", family.name, attempt + 1, time.monotonic() - start)
60
  except Exception as exc:
61
- logger.warning("Network diagnostic: family=%s attempt=%d error=%s duration=%.2fs", family.name, attempt + 1, type(exc).__name__, time.monotonic() - start)
62
  except Exception as exc:
63
  logger.warning("Network diagnostic: DNS error=%s", type(exc).__name__)
64
 
 
43
  host = "api.cloudflare.com"
44
  try:
45
  addresses = socket.getaddrinfo(host, 443, type=socket.SOCK_STREAM)
46
+ candidates = []
47
+ seen = set()
48
  for family, kind, proto, _, address in addresses:
49
+ if family in (socket.AF_INET, socket.AF_INET6) and (family, address[0]) not in seen:
50
+ seen.add((family, address[0]))
51
+ candidates.append((family, kind, proto, address))
52
+ logger.warning("Network diagnostic: address count=%d", len(candidates))
53
+ for index, (family, kind, proto, address) in enumerate(candidates):
54
  for attempt in range(2):
55
  start = time.monotonic()
56
  try:
 
58
  sock.settimeout(12)
59
  sock.connect(address)
60
  with ssl.create_default_context().wrap_socket(sock, server_hostname=host):
61
+ logger.warning("Network diagnostic: index=%d family=%s attempt=%d TLS=ok duration=%.2fs", index, family.name, attempt + 1, time.monotonic() - start)
62
  except Exception as exc:
63
+ logger.warning("Network diagnostic: index=%d family=%s attempt=%d error=%s duration=%.2fs", index, family.name, attempt + 1, type(exc).__name__, time.monotonic() - start)
64
  except Exception as exc:
65
  logger.warning("Network diagnostic: DNS error=%s", type(exc).__name__)
66