go-ping / ping

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

Some packet loss causes ping to hang forever #219

Closed kim0 closed 1 year ago

kim0 commented 1 year ago

I was see'ing this while using the library, but thought to test through the cmd app, and sure enough I got the same behavior. I ping some IP over my VPN network. Then mid-way, I disconnect the VPN. This makes the ping replies stop coming back. A few seconds later, I turn on VPN again, and replies do continue on the screen. But once the number of pings is finished, the command hangs forever!

$ ~/go/bin/ping -c 30 172.29.0.3
PING 172.29.0.3 (172.29.0.3):
32 bytes from 172.29.0.3: icmp_seq=0 time=445.737ms ttl=63
32 bytes from 172.29.0.3: icmp_seq=1 time=221.393ms ttl=63
32 bytes from 172.29.0.3: icmp_seq=2 time=222.131ms ttl=63
32 bytes from 172.29.0.3: icmp_seq=3 time=221.265ms ttl=63
32 bytes from 172.29.0.3: icmp_seq=4 time=221.325ms ttl=63

32 bytes from 172.29.0.3: icmp_seq=11 time=441.525ms ttl=63
32 bytes from 172.29.0.3: icmp_seq=12 time=222.524ms ttl=63
32 bytes from 172.29.0.3: icmp_seq=13 time=219.909ms ttl=63
32 bytes from 172.29.0.3: icmp_seq=14 time=223.33ms ttl=63
32 bytes from 172.29.0.3: icmp_seq=15 time=269.944ms ttl=63
32 bytes from 172.29.0.3: icmp_seq=16 time=226.788ms ttl=63
32 bytes from 172.29.0.3: icmp_seq=17 time=227.427ms ttl=63
32 bytes from 172.29.0.3: icmp_seq=18 time=225.9ms ttl=63
32 bytes from 172.29.0.3: icmp_seq=19 time=226.182ms ttl=63
32 bytes from 172.29.0.3: icmp_seq=20 time=236.567ms ttl=63
32 bytes from 172.29.0.3: icmp_seq=21 time=226.552ms ttl=63
32 bytes from 172.29.0.3: icmp_seq=22 time=225.182ms ttl=63
32 bytes from 172.29.0.3: icmp_seq=23 time=256.778ms ttl=63
32 bytes from 172.29.0.3: icmp_seq=24 time=280.699ms ttl=63
32 bytes from 172.29.0.3: icmp_seq=25 time=307.8ms ttl=63
32 bytes from 172.29.0.3: icmp_seq=26 time=329.781ms ttl=63
32 bytes from 172.29.0.3: icmp_seq=27 time=250.776ms ttl=63
32 bytes from 172.29.0.3: icmp_seq=28 time=226.709ms ttl=63
32 bytes from 172.29.0.3: icmp_seq=29 time=227.708ms ttl=63

^ Never finishes!

kim0 commented 1 year ago

Forgot to mention this is on MacOS 13.0, Go 1.19.1

hiteshhedwig commented 1 year ago

Hi, @kim0

Did you try setting Timeout for the NewPinger.

pinger = ping.NewPinger(addr)
pinger.Timeout = time.Duration(200 * time.Millisecond)
kim0 commented 1 year ago

Yes timeout does work, but ofc the bug still stands. Thanks

On Mon, Sep 19, 2022, 7:58 PM Hitesh Kumar @.***> wrote:

Hi,

Did you try setting Timeout for the NewPinger.

pinger = ping.NewPinger(addr) pinger.Timeout = time.Duration(200 * time.Millisecond)

— Reply to this email directly, view it on GitHub https://github.com/go-ping/ping/issues/219#issuecomment-1251358206, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAAOSEY46NT5YXDJSNQBZTTV7CSTHANCNFSM6AAAAAAQPRMCWM . You are receiving this because you authored the thread.Message ID: @.***>