go-ping / ping

ICMP Ping library for Go
MIT License
1.33k stars 345 forks source link

Deadlock fix #85

Closed stenya closed 4 years ago

stenya commented 4 years ago

Deadlock observed when starting multiple ping routines. It happens when writting to recv channel (which is full) and no active readers for this channel.

Example to reproduce the issue :

var waiter sync.WaitGroup
pingFunc := func() {
    defer waiter.Done()

    pinger, err := ping.NewPinger("8.8.8.8")
    if err != nil {
        return
    }

    pinger.SetPrivileged(true)
    pinger.Count = 5
    pinger.Interval = time.Second
    pinger.Timeout = time.Second * 4

    pinger.Run()
}

for i := 0; i < 1000; i++ {
    waiter.Add(1)
    go pingFunc()
}

waiter.Wait() // deadlock here! (reproducible almost every time)
CHTJonas commented 4 years ago

Hi @stenya! Would you feel comfortable adding something to the test suite that checks for this deadlock?

SuperQ commented 4 years ago

This is also duplicated by #84.

SuperQ commented 4 years ago

Going to merge this, and see if we can get #84 re-based on top.