Commit b62f86cd authored by Jacob Vosmaer's avatar Jacob Vosmaer

Add brute force process group clean-up

parent 8b14e2e8
......@@ -189,6 +189,7 @@ func handleGetInfoRefs(env gitEnv, _ string, path string, w http.ResponseWriter,
return
}
defer cmd.Wait()
defer sigKillProcessGroup(cmd) // Ensure brute force subprocess clean-up
// Start writing the response
w.Header().Add("Content-Type", fmt.Sprintf("application/x-%s-advertisement", rpc))
......@@ -258,6 +259,7 @@ func handlePostRPC(env gitEnv, rpc string, path string, w http.ResponseWriter, r
return
}
defer cmd.Wait()
defer sigKillProcessGroup(cmd) // Ensure brute force subprocess clean-up
// Write the client request body to Git's standard input
if _, err := io.Copy(stdin, body); err != nil {
......@@ -296,3 +298,19 @@ func fail500(w http.ResponseWriter, err error) {
func setHeaderNoCache(w http.ResponseWriter) {
w.Header().Add("Cache-Control", "no-cache")
}
func sigKillProcessGroup(cmd *exec.Cmd) {
if cmd == nil {
return
}
process := cmd.Process
if process == nil {
return
}
if process.Pid > 0 {
// Send SIGKILL (kill -9) to the process group of cmd
syscall.Kill(-process.Pid, syscall.SIGKILL)
}
}
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