From 485830452ebeb21975de35f91266df3f9b88b49f Mon Sep 17 00:00:00 2001 From: xiaomiku01 Date: Sat, 11 Apr 2026 21:21:15 +0800 Subject: [PATCH] fix(agent): exclude DNS resolution from TCP probe latency Resolve the target hostname before starting the timer so the measurement reflects pure TCP handshake time only. Co-Authored-By: Claude Opus 4.6 (1M context) --- agent/probe.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/agent/probe.go b/agent/probe.go index 05f6d7c5..6ebfc57d 100644 --- a/agent/probe.go +++ b/agent/probe.go @@ -201,9 +201,17 @@ func (pm *ProbeManager) executeProbe(task *probeTask) { task.mu.Unlock() } -// probeTCP measures TCP connection latency. Returns -1 on failure. +// probeTCP measures pure TCP handshake latency (excluding DNS resolution). +// Returns -1 on failure. func probeTCP(target string, port uint16) float64 { - addr := net.JoinHostPort(target, fmt.Sprintf("%d", port)) + // Resolve DNS first, outside the timing window + ips, err := net.LookupHost(target) + if err != nil || len(ips) == 0 { + return -1 + } + addr := net.JoinHostPort(ips[0], fmt.Sprintf("%d", port)) + + // Measure only the TCP handshake start := time.Now() conn, err := net.DialTimeout("tcp", addr, 3*time.Second) if err != nil {