From 1aae73e1d141ed39cd6086189222021b8b13c11d Mon Sep 17 00:00:00 2001 From: Runxi Yu Date: Sun, 10 Aug 2025 05:34:56 +0800 Subject: [PATCH] http upload pack: Attempt to fix deadlock --- forged/internal/unsorted/http_handle_repo_upload_pack.go | 35 +++-------------------------------- diff --git a/forged/internal/unsorted/http_handle_repo_upload_pack.go b/forged/internal/unsorted/http_handle_repo_upload_pack.go index 02a09c57c7749f0542672e25ba3edb429564394c..62547d853f3f2b824adf81cb6dbe1b7212298440 100644 --- a/forged/internal/unsorted/http_handle_repo_upload_pack.go +++ b/forged/internal/unsorted/http_handle_repo_upload_pack.go @@ -5,7 +5,6 @@ package unsorted import ( "bytes" - "io" "log" "net/http" "os" @@ -20,8 +19,6 @@ func (s *Server) httpHandleUploadPack(writer http.ResponseWriter, request *http.Request, params map[string]any) (err error) { var groupPath []string var repoName string var repoPath string - var stdout io.ReadCloser - var stdin io.WriteCloser var cmd *exec.Cmd groupPath, repoName = params["group_path"].([]string), params["repo_name"].(string) @@ -70,40 +67,14 @@ writer.WriteHeader(http.StatusOK) cmd = exec.Command("git", "upload-pack", "--stateless-rpc", repoPath) cmd.Env = append(os.Environ(), "LINDENII_FORGE_HOOKS_SOCKET_PATH="+s.config.Hooks.Socket) - if stdout, err = cmd.StdoutPipe(); err != nil { - return err - } - defer func() { - _ = stdout.Close() - }() var stderrBuf bytes.Buffer cmd.Stderr = &stderrBuf - if stdin, err = cmd.StdinPipe(); err != nil { - return err - } - defer func() { - _ = stdin.Close() - }() + cmd.Stdout = writer + cmd.Stdin = request.Body - if err = cmd.Start(); err != nil { - return err - } - - if _, err = io.Copy(stdin, request.Body); err != nil { - return err - } - - if err = stdin.Close(); err != nil { - return err - } - - if _, err = io.Copy(writer, stdout); err != nil { - return err - } - - if err = cmd.Wait(); err != nil { + if err = cmd.Run(); err != nil { log.Println(stderrBuf.String()) return err } -- 2.48.1