mirror of
https://github.com/henrygd/beszel.git
synced 2026-04-21 04:01:50 +02:00
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:
@@ -201,9 +201,17 @@ func (pm *ProbeManager) executeProbe(task *probeTask) {
|
|||||||
task.mu.Unlock()
|
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 {
|
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()
|
start := time.Now()
|
||||||
conn, err := net.DialTimeout("tcp", addr, 3*time.Second)
|
conn, err := net.DialTimeout("tcp", addr, 3*time.Second)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user