Skip to content

Commit b36c75f

Browse files
authored
Merge pull request #48 from nulab/issue-46/safe-stop-running-child-process
Stop the running child process when the connection is broken (#46)
2 parents 7dc706c + f656fd3 commit b36c75f

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

Diff for: githttpxfer/githttpxfer.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,11 @@ func (ghx *GitHTTPXfer) serviceRPC(ctx Context, rpc string) {
266266
args := []string{rpc, "--stateless-rpc", "."}
267267
cmd := ghx.Git.GitCommand(repoPath, args...)
268268
cmd.Env = ctx.Env()
269-
defer cleanUpProcessGroup(cmd)
269+
defer cmd.Wait()
270+
go func() {
271+
<-req.Context().Done()
272+
cleanUpProcessGroup(cmd)
273+
}()
270274

271275
stdin, err := cmd.StdinPipe()
272276
if err != nil {

Diff for: githttpxfer/support.go

-1
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,4 @@ func cleanUpProcessGroup(cmd *exec.Cmd) {
2222
if process := cmd.Process; process != nil && process.Pid > 0 {
2323
syscall.Kill(-process.Pid, syscall.SIGTERM)
2424
}
25-
cmd.Wait()
2625
}

0 commit comments

Comments
 (0)