Commit e34d9bc4 authored by Jacob Vosmaer's avatar Jacob Vosmaer

Wait() after killing processes

parent b62f86cd
...@@ -188,8 +188,7 @@ func handleGetInfoRefs(env gitEnv, _ string, path string, w http.ResponseWriter, ...@@ -188,8 +188,7 @@ func handleGetInfoRefs(env gitEnv, _ string, path string, w http.ResponseWriter,
fail500(w, err) fail500(w, err)
return return
} }
defer cmd.Wait() defer cleanUpProcessGroup(cmd) // Ensure brute force subprocess clean-up
defer sigKillProcessGroup(cmd) // Ensure brute force subprocess clean-up
// Start writing the response // Start writing the response
w.Header().Add("Content-Type", fmt.Sprintf("application/x-%s-advertisement", rpc)) w.Header().Add("Content-Type", fmt.Sprintf("application/x-%s-advertisement", rpc))
...@@ -258,8 +257,7 @@ func handlePostRPC(env gitEnv, rpc string, path string, w http.ResponseWriter, r ...@@ -258,8 +257,7 @@ func handlePostRPC(env gitEnv, rpc string, path string, w http.ResponseWriter, r
fail500(w, err) fail500(w, err)
return return
} }
defer cmd.Wait() defer cleanUpProcessGroup(cmd) // Ensure brute force subprocess clean-up
defer sigKillProcessGroup(cmd) // Ensure brute force subprocess clean-up
// Write the client request body to Git's standard input // Write the client request body to Git's standard input
if _, err := io.Copy(stdin, body); err != nil { if _, err := io.Copy(stdin, body); err != nil {
...@@ -299,18 +297,17 @@ func setHeaderNoCache(w http.ResponseWriter) { ...@@ -299,18 +297,17 @@ func setHeaderNoCache(w http.ResponseWriter) {
w.Header().Add("Cache-Control", "no-cache") w.Header().Add("Cache-Control", "no-cache")
} }
func sigKillProcessGroup(cmd *exec.Cmd) { func cleanUpProcessGroup(cmd *exec.Cmd) {
if cmd == nil { if cmd == nil {
return return
} }
process := cmd.Process process := cmd.Process
if process == nil { if process != nil && process.Pid > 0 {
return
}
if process.Pid > 0 {
// Send SIGKILL (kill -9) to the process group of cmd // Send SIGKILL (kill -9) to the process group of cmd
syscall.Kill(-process.Pid, syscall.SIGKILL) syscall.Kill(-process.Pid, syscall.SIGKILL)
} }
// reap our child process
cmd.Wait()
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment