Skip to content

Commit 099d627

Browse files
committed
fix: treat connection refused as transient across all DNS protocols
DoH, DoH3, and DoQ would exit immediately when a service was unavailable, making them behave differently from regular UDP DNS. This was inconsistent and prevented using dnsping as a monitoring tool for intermittent service availability. Now all protocols continue pinging when connection is refused, showing "Connection refused" messages and collecting packet loss statistics. Makes behavior uniform whether you're pinging over UDP, TCP, TLS, QUIC, or HTTP.
1 parent 87b2285 commit 099d627

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

dnsping.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,9 @@ def main() -> None:
449449
except dns.query.NoDOH:
450450
die("ERROR: python httpx module not available")
451451
except httpx.ConnectError:
452-
die(f"DoH connection failed on port {dst_port}")
452+
if not quiet:
453+
print("Connection refused", flush=True)
454+
continue
453455
else:
454456
unsupported_feature("DNS-over-HTTPS (DoH)")
455457

@@ -465,7 +467,9 @@ def main() -> None:
465467
source=src_ip, source_port=src_port,
466468
http_version=dns.query.HTTPVersion.H3)
467469
except ConnectionRefusedError:
468-
die(f"DoH3 connection refused on port {dst_port}")
470+
if not quiet:
471+
print("Connection refused", flush=True)
472+
continue
469473
else:
470474
unsupported_feature("DNS-over-HTTPS/3 (DoH3)")
471475

@@ -482,7 +486,9 @@ def main() -> None:
482486
print("Request timeout", flush=True)
483487
continue
484488
except ConnectionRefusedError:
485-
die(f"DoQ connection refused on port {dst_port}")
489+
if not quiet:
490+
print("Connection refused", flush=True)
491+
continue
486492
except Exception as e:
487493
# Catch QUIC-specific exceptions like UnexpectedEOF
488494
if e.__class__.__name__ == 'UnexpectedEOF':

0 commit comments

Comments
 (0)