go-ping / ping

ICMP Ping library for Go
MIT License
1.31k stars 344 forks source link

avgRtt is sometimes negative #194

Closed YouZhengChuan closed 1 year ago

YouZhengChuan commented 2 years ago

image The probability is very low, but there is a possibility of negative numbers.

YouZhengChuan commented 2 years ago

image

rt_min is negative,So Packet.Rtt is wrong。

CHTJonas commented 2 years ago

What endpoint(s) are you pinging when you experience this? On which platform (OS/architecture) are you experiencing this? Could you include full sample code that replicates the issue?

YouZhengChuan commented 1 year ago

image

From recent results, this only happens in devices with "ARM64" architecture, the OS version is "Debian GNU/Linux 9 (stretch)"; the destination addresses are both IP4 and IP6.

pinger code:

require (
  github.com/go-ping/ping v0.0.0-20210407214646-e4e642a95741
)
$ go version
go version go1.15.5 linux/amd64
pinger := goPing.New(IP)
pinger.SetNetwork(network) // ip4, ip6, ip
if err := pinger.Resolve(); err != nil { return err }
pinger.Source = bindAddr
pinger.SetPrivileged(true)
pinger.Timeout = timeout // the usual value is 5 min
pinger.Interval = interval // the usual value is  1 sec
pinger.Count = int(pktCount) // the usual value is 100
pinger.Size = int(pktBytes) // the usual value is 64
pinger.OnFinish = func(stats *goPing.Statistics) {
    result.PktLoss = stats.PacketLoss
    result.RtMax = int64(stats.MaxRtt) / 1e6 // Milliseconds
    result.RtAvg = int64(stats.AvgRtt) / 1e6 // Milliseconds
    result.RtMin = int64(stats.MinRtt) / 1e6 // Milliseconds
}
if err := pinger.Run(); err != nil { return err }