aboutsummaryrefslogtreecommitdiffstats
path: root/models/git_diff.go
diff options
context:
space:
mode:
authorUnknown <joe2010xtmf@163.com>2014-07-06 17:32:36 -0400
committerUnknown <joe2010xtmf@163.com>2014-07-06 17:32:36 -0400
commit097c8e05e6791efe3876eedf989e2b69190f7f8f (patch)
treedcf67952ffbfbfd6cd056006073eda7393b723bc /models/git_diff.go
parentfd5412ec47018a72c1f05aca487e10ea0a665e45 (diff)
downloadgitea-097c8e05e6791efe3876eedf989e2b69190f7f8f.tar.gz
gitea-097c8e05e6791efe3876eedf989e2b69190f7f8f.zip
Able to set timeout for process monitor
Diffstat (limited to 'models/git_diff.go')
-rw-r--r--models/git_diff.go29
1 files changed, 23 insertions, 6 deletions
diff --git a/models/git_diff.go b/models/git_diff.go
index ed114b7504..303d61d5de 100644
--- a/models/git_diff.go
+++ b/models/git_diff.go
@@ -11,6 +11,7 @@ import (
"os"
"os/exec"
"strings"
+ "time"
"github.com/gogits/git"
@@ -170,10 +171,6 @@ func ParsePatch(pid int64, cmd *exec.Cmd, reader io.Reader) (*Diff, error) {
}
}
- // In case process became zombie.
- if err := process.Kill(pid); err != nil {
- log.Error("git_diff.ParsePatch(Kill): %v", err)
- }
return diff, nil
}
@@ -201,10 +198,30 @@ func GetDiff(repoPath, commitid string) (*Diff, error) {
cmd.Stdout = wr
cmd.Stdin = os.Stdin
cmd.Stderr = os.Stderr
+
+ done := make(chan error)
go func() {
- cmd.Run()
+ cmd.Start()
+ done <- cmd.Wait()
wr.Close()
}()
defer rd.Close()
- return ParsePatch(process.Add(fmt.Sprintf("GetDiff(%s)", repoPath), cmd), cmd, rd)
+
+ desc := fmt.Sprintf("GetDiff(%s)", repoPath)
+ pid := process.Add(desc, cmd)
+ go func() {
+ // In case process became zombie.
+ select {
+ case <-time.After(5 * time.Minute):
+ if errKill := process.Kill(pid); errKill != nil {
+ log.Error("git_diff.ParsePatch(Kill): %v", err)
+ }
+ <-done
+ // return "", ErrExecTimeout.Error(), ErrExecTimeout
+ case err = <-done:
+ process.Remove(pid)
+ }
+ }()
+
+ return ParsePatch(pid, cmd, rd)
}