Skip to content
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

Timeout prevents application exit #11

Closed
onitake opened this issue Jun 23, 2017 · 7 comments
Closed

Timeout prevents application exit #11

onitake opened this issue Jun 23, 2017 · 7 comments

Comments

@onitake
Copy link

onitake commented Jun 23, 2017

When sending an unsuccessful ping request, it is no longer possible to end an application in a proper fashion, i.e. Ctrl-C does not work. I suspect the timeout code does not end all goroutines properly.

Example code:

	pinger, err := ping.NewPinger(addr)
	if err != nil {
		log.Fatal(err)
	}
	pinger.Timeout = time.Seconds * 10
	pinger.Count = 3
	pinger.SetPrivileged(true)
	pinger.Run()
	stats := pinger.Statistics()
	log.Println(stats)
@devinodaniel
Copy link

Also experiencing this. @onitake did you ever trace or confirm that pinger.Timeout is the issue?

@onitake
Copy link
Author

onitake commented Jan 17, 2018

I didn't; for my use case, I opted for a simpler approach with an exec of ping instead.
This has the advantage of not requiring superuser privileges. The disadvantage is that you need to depend on a minimal shell environment.
But it should be fairly easy to trace with pprof.

@jmunsin
Copy link

jmunsin commented Mar 4, 2018

I had a similar problem, the following change seems to fix it:

diff --git a/ping.go b/ping.go
index c8cae5d..2cd213a 100644
--- a/ping.go
+++ b/ping.go
@@ -289,6 +289,7 @@ func (p *Pinger) run() {
        c := make(chan os.Signal, 1)
        signal.Notify(c, os.Interrupt)
        signal.Notify(c, syscall.SIGTERM)
+       defer signal.Stop(c)

        for {
                select {

@robisonjoel
Copy link

I tried jmunsin's fix and con confirm it has the desired results

@MichaelHipp
Copy link

MichaelHipp commented Jun 17, 2018

I can confirm this problem also. Nearly impossible to make a program exit once ping has been Run.

@onitake
Copy link
Author

onitake commented Jun 20, 2018

@jmunsin Can you turn this into a PR and submit it?
This is something that should finally be fixed...

@sparrc
Copy link
Member

sparrc commented Nov 6, 2018

Thank you for the report. The library was erronously previously capturing the ctrl-C signal. This was fixed by #37

@sparrc sparrc closed this as completed Nov 6, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants