Skip to content

Commit

Permalink
Merge pull request #48 from nulab/issue-46/safe-stop-running-child-pr…
Browse files Browse the repository at this point in the history
…ocess

Stop the running child process when the connection is broken (#46)
  • Loading branch information
vvatanabe authored Sep 28, 2020
2 parents 7dc706c + f656fd3 commit b36c75f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
6 changes: 5 additions & 1 deletion githttpxfer/githttpxfer.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,11 @@ func (ghx *GitHTTPXfer) serviceRPC(ctx Context, rpc string) {
args := []string{rpc, "--stateless-rpc", "."}
cmd := ghx.Git.GitCommand(repoPath, args...)
cmd.Env = ctx.Env()
defer cleanUpProcessGroup(cmd)
defer cmd.Wait()
go func() {
<-req.Context().Done()
cleanUpProcessGroup(cmd)
}()

stdin, err := cmd.StdinPipe()
if err != nil {
Expand Down
1 change: 0 additions & 1 deletion githttpxfer/support.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,4 @@ func cleanUpProcessGroup(cmd *exec.Cmd) {
if process := cmd.Process; process != nil && process.Pid > 0 {
syscall.Kill(-process.Pid, syscall.SIGTERM)
}
cmd.Wait()
}

0 comments on commit b36c75f

Please sign in to comment.