-
Notifications
You must be signed in to change notification settings - Fork 122
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
RunLoop issue, after Stop() is issued #29
Comments
Forgot to write, that in my code OnIdle function calls p.Stop() after N idle calls. Regards, |
I use RunLoop in the same way and p.Stop() don't stop the loop. Here a little example:
Stdout result is :
I just ping loopback with 2 sec of "timeout" and "loop done" was never printed. |
I'm facing the same issue, but I see in mainloop this check: So shouldn't func (p *Pinger) Stop() return something like <-p.ctx.stop instead of ? |
cova-fe: <-p.ctx.done to: p.ctx.done <- true You see, the problem in my opinion is in the fact, that Done() function in fact returns done channel, which must contain a boolean true value if you want to stop the loop. I think that your loop should look similar to bewiwi's, so checking the p.Done() and not the p.ctx.stop itself. This patch is tested and the code is running in production. Regards, |
@asmpro Hi, I have a func here which has to run forever runloop and break whenever there is ping failure. The problem is it works fine till it can ping and goes to idle but doesn't stop or exit. Here is the code any help is appreciated. Thanks func pingIP(ipadd string) { |
@suvvari8 Hi, First patch fastping.go as I mentioned in my first comment. Then use RunLoop this way: type PingData struct { p := fastping.NewPinger() pings := 0 p.RunLoop() |
I seem to have found the cause of deadlock. Since the code is executed in parallel, the operation time.NewTicker(p.MaxRTT) conflicts with "close (p.ctx.stop)" and when processing anything in OnIdle = func () {
} we get deadlock Solution: do not use blocking operations in pings := 0
p.OnIdle = func() {
pings++
if pings >= npings {
- p.Stop()
+ go p.Stop()
}
} or not use |
Hi, I noticed, that Stop() function does not write bool to done channel, but instead reads from it.
In my code I am using the following:
which deadlocks, so I suggest Stop() function should be changed to:
func (p *Pinger) Stop() {
p.debugln("Stop(): close(p.ctx.stop)")
close(p.ctx.stop)
p.debugln("Stop(): p.ctx.done <- true")
p.ctx.done <- true
}
Regards,
Uros
The text was updated successfully, but these errors were encountered: