From 015027356a38c6b336fa5ad57a10085e47f8f2fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ask=20Bj=C3=B8rn=20Hansen?= Date: Sun, 18 Aug 2024 16:25:07 -0700 Subject: [PATCH] monitor: Handle EOF errors, improve network error handling https://community.ntppool.org/t/uk-pool-ntp-org-delivering-wrong-time/3478/19 --- client/monitor/monitor.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/client/monitor/monitor.go b/client/monitor/monitor.go index d2033ff..7f0daad 100644 --- a/client/monitor/monitor.go +++ b/client/monitor/monitor.go @@ -93,7 +93,9 @@ func CheckHost(ctx context.Context, ip *netip.Addr, cfg *pb.Config, traceAttribu resp, err := ntp.QueryWithOptions(ipStr, opts) if err != nil { r := &response{ - Status: &pb.ServerStatus{}, + Status: &pb.ServerStatus{ + NoResponse: true, + }, } r.Status.SetIP(ip) if resp != nil { @@ -104,7 +106,10 @@ func CheckHost(ctx context.Context, ip *netip.Addr, cfg *pb.Config, traceAttribu if netErr, ok := err.(*net.OpError); ok { // drop the protocol and addresses r.Error = fmt.Errorf("network: %w", netErr.Err) + } else { + r.Error = err } + r.Status.Error = r.Error.Error() responses = append(responses, r) @@ -151,7 +156,7 @@ func CheckHost(ctx context.Context, ip *netip.Addr, cfg *pb.Config, traceAttribu var best *response - // log.Printf("for %s we collected %d samples, now find the best result", ip.String(), len(statuses)) + // log.Debug("collection done, now find the best result", "ip", ip.String(), "count", len(responses)) // todo: if there are more than 2 (3?) samples with an offset, throw // away the offset outlier(s)