all repos — elgit @ ebab20415fab0f71ae0d0319cb129ba1bf12bc16

fork of legit: web frontend for git, written in go

ensure git processes are cleaned up with request after timeout

Alan Pearce
commit

ebab20415fab0f71ae0d0319cb129ba1bf12bc16

parent

3251083f4870523a0f6f4fa9b8252ff6e89505fa

1 file changed, 12 insertions(+), 4 deletions(-)

changed files
M git/service/service.gogit/service/service.go
@@ -2,6 +2,7 @@ package service
import ( "bytes" + "context" "errors" "fmt" "io"
@@ -10,8 +11,11 @@ "net/http"
"os/exec" "strings" "syscall" + "time" ) +const timeout = 1 * time.Minute + // Mostly from charmbracelet/soft-serve and sosedoff/gitkit. type ServiceCommand struct {
@@ -20,8 +24,10 @@ Stdin io.Reader
Stdout http.ResponseWriter } -func (c *ServiceCommand) InfoRefs() error { - cmd := exec.Command("git", []string{ +func (c *ServiceCommand) InfoRefs(ctx context.Context) error { + ctx, cancel := context.WithTimeout(ctx, timeout) + defer cancel() + cmd := exec.CommandContext(ctx, "git", []string{ "upload-pack", "--stateless-rpc", "--advertise-refs",
@@ -73,8 +79,10 @@
return nil } -func (c *ServiceCommand) UploadPack() (err error) { - cmd := exec.Command("git", []string{ +func (c *ServiceCommand) UploadPack(ctx context.Context) (err error) { + ctx, cancel := context.WithTimeout(ctx, timeout) + defer cancel() + cmd := exec.CommandContext(ctx, "git", []string{ "-c", "uploadpack.allowFilter=true", "upload-pack", "--stateless-rpc",