summaryrefslogtreecommitdiffstats
path: root/modules/process
diff options
context:
space:
mode:
authorzeripath <art27@cantab.net>2022-06-03 15:36:18 +0100
committerGitHub <noreply@github.com>2022-06-03 15:36:18 +0100
commit1d04e8641d4abab6ce978bc2dc5523c2ddb2f628 (patch)
tree742564159535d13dd060074187be79616da2bb3f /modules/process
parent085924b1b370310c989fa5e75bb33323746382b0 (diff)
downloadgitea-1d04e8641d4abab6ce978bc2dc5523c2ddb2f628.tar.gz
gitea-1d04e8641d4abab6ce978bc2dc5523c2ddb2f628.zip
Set Setpgid on child git processes (#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 #19077 Signed-off-by: Andrew Thornton <art27@cantab.net>
Diffstat (limited to 'modules/process')
-rw-r--r--modules/process/manager_exec.go1
-rw-r--r--modules/process/manager_unix.go18
-rw-r--r--modules/process/manager_windows.go16
3 files changed, 35 insertions, 0 deletions
diff --git a/modules/process/manager_exec.go b/modules/process/manager_exec.go
index 61ddae646f..77e3d3193a 100644
--- a/modules/process/manager_exec.go
+++ b/modules/process/manager_exec.go
@@ -58,6 +58,7 @@ func (pm *Manager) ExecDirEnvStdIn(ctx context.Context, timeout time.Duration, d
if stdIn != nil {
cmd.Stdin = stdIn
}
+ SetSysProcAttribute(cmd)
if err := cmd.Start(); err != nil {
return "", "", err
diff --git a/modules/process/manager_unix.go b/modules/process/manager_unix.go
new file mode 100644
index 0000000000..1e7c77fdbf
--- /dev/null
+++ b/modules/process/manager_unix.go
@@ -0,0 +1,18 @@
+// Copyright 2022 The Gitea Authors. All rights reserved.
+// Use of this source code is governed by a MIT-style
+// license that can be found in the LICENSE file.
+
+//go:build !windows
+
+package process
+
+import (
+ "os/exec"
+ "syscall"
+)
+
+// SetSysProcAttribute sets the common SysProcAttrs for commands
+func SetSysProcAttribute(cmd *exec.Cmd) {
+ // When Gitea runs SubProcessA -> SubProcessB and SubProcessA gets killed by context timeout, use setpgid to make sure the sub processes can be reaped instead of leaving defunct(zombie) processes.
+ cmd.SysProcAttr = &syscall.SysProcAttr{Setpgid: true}
+}
diff --git a/modules/process/manager_windows.go b/modules/process/manager_windows.go
new file mode 100644
index 0000000000..35f66d9fa5
--- /dev/null
+++ b/modules/process/manager_windows.go
@@ -0,0 +1,16 @@
+// Copyright 2022 The Gitea Authors. All rights reserved.
+// Use of this source code is governed by a MIT-style
+// license that can be found in the LICENSE file.
+
+//go:build windows
+
+package process
+
+import (
+ "os/exec"
+)
+
+// SetSysProcAttribute sets the common SysProcAttrs for commands
+func SetSysProcAttribute(cmd *exec.Cmd) {
+ // Do nothing
+}