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) <noreply@anthropic.com>
This commit is contained in:
xiaomiku01
2026-04-11 21:21:15 +08:00
parent 2fd00cd0b5
commit 485830452e

View File

@@ -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 {