tangled
alpha
login
or
join now
back
round
0
view raw
knotserver/git: wait for git cmd to complete after streaming output
#659
merged
opened by
oppi.li
3 months ago
targeting
master
from
push-nqqnxowuwkvz
could be a source of zombie processes.
Signed-off-by: oppiliappan
me@oppi.li
options
unified
split
Changed files
+21
-2
knotserver
git
last_commit.go
+21
-2
knotserver/git/last_commit.go
···
30
commitCache = cache
31
}
32
33
-
func (g *GitRepo) streamingGitLog(ctx context.Context, extraArgs ...string) (io.Reader, error) {
0
0
0
0
0
0
0
0
0
0
0
0
0
0
34
args := []string{}
35
args = append(args, "log")
36
args = append(args, g.h.String())
···
48
return nil, err
49
}
50
51
-
return stdout, nil
0
0
0
0
52
}
53
54
type commit struct {
···
104
if err != nil {
105
return nil, err
106
}
0
107
108
reader := bufio.NewReader(output)
109
var current commit
···
30
commitCache = cache
31
}
32
33
+
// processReader wraps a reader and ensures the associated process is cleaned up
34
+
type processReader struct {
35
+
io.Reader
36
+
cmd *exec.Cmd
37
+
stdout io.ReadCloser
38
+
}
39
+
40
+
func (pr *processReader) Close() error {
41
+
if err := pr.stdout.Close(); err != nil {
42
+
return err
43
+
}
44
+
return pr.cmd.Wait()
45
+
}
46
+
47
+
func (g *GitRepo) streamingGitLog(ctx context.Context, extraArgs ...string) (io.ReadCloser, error) {
48
args := []string{}
49
args = append(args, "log")
50
args = append(args, g.h.String())
···
62
return nil, err
63
}
64
65
+
return &processReader{
66
+
Reader: stdout,
67
+
cmd: cmd,
68
+
stdout: stdout,
69
+
}, nil
70
}
71
72
type commit struct {
···
122
if err != nil {
123
return nil, err
124
}
125
+
defer output.Close() // Ensure the git process is properly cleaned up
126
127
reader := bufio.NewReader(output)
128
var current commit