-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
Set Setpgid on child git processes #19865
Conversation
When Gitea is running as PID 1 git will occassionally orphan child processes leading to (defunct) processes. This PR simply sets Setpgid to true on these child processes meaning that these defunct processes will also be correctly killed. Fix go-gitea#19077 Signed-off-by: Andrew Thornton <art27@cantab.net>
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately don't have a windows machine to test.
Hmm... it looks like it doesn't compile on Windows. -- have adjusted this to make it work on doze |
Signed-off-by: Andrew Thornton <art27@cantab.net>
Signed-off-by: Andrew Thornton <art27@cantab.net>
Co-authored-by: singuliere <35190819+singuliere@users.noreply.github.com>
Looks good to me while I think there could be a comment in code to remember the reason why it is needed. And I am not sure whether there could be a case that: Gitea -> SubProcessA -> SubProcessB , then although SubProcessA is killed (and there is no defunct due to Setpgid), SubProcessB is still running for a long time (still somewhat resource leaking?). |
This comment was marked as outdated.
This comment was marked as outdated.
Signed-off-by: Andrew Thornton <art27@cantab.net>
You misunderstand the purpose of Setpgid, let me explain:
SubProcessA is not defunct/zombie because Gitea waits for it, not because of Setpgid
the purpose of Setpgid is to make sure SubProcessB is also killed when SubProcessA is killed. For a more detailed explanation and a reproducer, please see https://hostea.org/blog/zombies/. |
func main() {
c := exec.Command("/bin/bash", "-c", `echo "sleep 100000" | bash`)
c.SysProcAttr = &syscall.SysProcAttr{Setpgid: true}
fmt.Printf("run err = %v", c.Run())
}
|
Would have worked as intended. |
func main() {
ctx, _ := context.WithTimeout(context.Background(), time.Second*2)
c := exec.CommandContext(ctx, "/bin/bash", "-c", `echo "while true; do echo running; sleep 1; done" | bash`)
c.SysProcAttr = &syscall.SysProcAttr{Setpgid: true}
c.Stdout = os.Stdout
fmt.Printf("run err = %v", c.Run())
}
|
|
Then, does Gitea use your |
This PR is not designed to kill children - but to simply allow for them to be reaped. We need to check that this does stop the (defunct) processes from occuring. |
I've just checked and it does. |
This comment was marked as off-topic.
This comment was marked as off-topic.
Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This comment was marked as off-topic.
This comment was marked as off-topic.
Backport go-gitea#19865 When Gitea is running as PID 1 git will occassionally orphan child processes leading to (defunct) processes. This PR simply sets Setpgid to true on these child processes meaning that these defunct processes will also be correctly reaped. Fix go-gitea#19077 Signed-off-by: Andrew Thornton <art27@cantab.net>
This comment was marked as off-topic.
This comment was marked as off-topic.
Please stop both of you - I've deleted the last few comments as I don't think there is anything to be gained from them. |
When Gitea is running as PID 1 git will occassionally orphan child processes leading
to (defunct) processes. This PR simply sets Setpgid to true on these child processes
meaning that these defunct processes will also be correctly reaped.
Fix #19077
Signed-off-by: Andrew Thornton art27@cantab.net