Skip to content
This repository was archived by the owner on Feb 8, 2021. It is now read-only.

Conversation

@pmorjan
Copy link
Contributor

@pmorjan pmorjan commented Feb 8, 2017

This patch adds a missing cmd.Wait() to wait for process completion
of containerd-nslistener. Without the wait every container leaves
a defunct process. This is required since #430 removed the global
SIGCHILD handler to avoid runtime panics.

Signed-off-by: Peter Morjan peter.morjan@de.ibm.com

go func() {
hp.nslistener.cmd.Process.Kill()
}()
if err := hp.nslistener.cmd.Process.Signal(syscall.Signal(0)); err == nil {
Copy link
Contributor

@laijs laijs Feb 10, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems strange that Process.Signal() and Process.Kill() are called at the same time.
if Process.Kill() is required when Process.Signal() is ignored by the target, I think a timer is also needed before Process.Kill().

hp.nslistener.cmd.Process.Kill()
}()
if err := hp.nslistener.cmd.Process.Signal(syscall.Signal(0)); err == nil {
hp.nslistener.cmd.Wait()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think cmd.Wait() should be called unconditionally, WDYT?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The signal(0) was just to ensure the process is really alive to prevent runtime panic on cmd.Wait.
Do you prefer it like this?

-               hp.nslistener.cmd.Process.Kill()
+               go func() {
+                       time.Sleep(time.Second*1)
+                       hp.nslistener.cmd.Process.Kill()
+               }()
+               hp.nslistener.cmd.Wait()

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use time.AfterFunc()

"if hp.nslistener != nil" ensures the process is/was launched

@laijs
Copy link
Contributor

laijs commented Feb 10, 2017

I like something like this

                hp.nslistener.cmd.Process.Signal(syscall.SIGTERM)
                timer := time.AfterFunc(time.Second*1, func() { hp.nslistener.cmd.Process.Kill() })
                hp.nslistener.cmd.Wait()
                timer.Stop()

or just kill&wait, no timer&signal

@pmorjan
Copy link
Contributor Author

pmorjan commented Feb 10, 2017

i don't get the difference. Please fix it as you like. Thanks.

@laijs
Copy link
Contributor

laijs commented Feb 10, 2017

there is no Signal() in your code, so it will always take 1 seconds to stop the nslistener

This patch adds a missing cmd.Wait() to wait for process completion
of containerd-nslistener. Without the wait every container leaves
a defunct process. This is required since #430 removed the global
SIGCHILD handler to avoid runtime panics.

Signed-off-by: Peter Morjan <peter.morjan@de.ibm.com>
@laijs
Copy link
Contributor

laijs commented Aug 3, 2017

@pmorjan runv cli is being improved continuously and had just been refactored #537 . As a result, it seams that the changes in this pr is outdated.

In the new code, this problem is fixed by this code:
https://github.com/hyperhq/runv/blob/master/cli/network.go#L320-L325

	defer func() {
		if err != nil {
			cmd.Process.Kill()
		}
		cmd.Wait()
	}()

Thank you for your contribution.

@laijs laijs closed this Aug 3, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants