Skip to content

Commit

Permalink
Deadlock fix (#85)
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
stenya committed Oct 1, 2020
1 parent e8ae07c commit 70ede2a
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion ping.go
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,11 @@ func (p *Pinger) recvICMP(
}
}

recv <- &packet{bytes: bytes, nbytes: n, ttl: ttl}
select {
case <-p.done:
return
case recv <- &packet{bytes: bytes, nbytes: n, ttl: ttl}:
}
}
}
}
Expand Down

0 comments on commit 70ede2a

Please sign in to comment.