mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-08-06 18:35:23 +02:00
Graceful: Cancel Process on monitor pages & HammerTime (#9213)
* Graceful: Create callbacks to with contexts * Graceful: Say when Gitea is completely finished * Graceful: Git and Process within HammerTime Force all git commands to terminate at HammerTime Force all process commands to terminate at HammerTime Move almost all git processes to run as git Commands * Graceful: Always Hammer after Shutdown * ProcessManager: Add cancel functionality * Fix tests * Make sure that process.Manager.Kill() cancels * Make threadsafe access to Processes and remove own unused Kill * Remove cmd from the process manager as it is no longer used * the default context is the correct context * get rid of double till
This commit is contained in:
parent
8f8c250ddb
commit
60c5339042
21 changed files with 536 additions and 198 deletions
|
@ -8,6 +8,7 @@ package repo
|
|||
import (
|
||||
"bytes"
|
||||
"compress/gzip"
|
||||
gocontext "context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"os"
|
||||
|
@ -24,6 +25,7 @@ import (
|
|||
"code.gitea.io/gitea/modules/context"
|
||||
"code.gitea.io/gitea/modules/git"
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
"code.gitea.io/gitea/modules/process"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
"code.gitea.io/gitea/modules/timeutil"
|
||||
)
|
||||
|
@ -463,8 +465,10 @@ func serviceRPC(h serviceHandler, service string) {
|
|||
// set this for allow pre-receive and post-receive execute
|
||||
h.environ = append(h.environ, "SSH_ORIGINAL_COMMAND="+service)
|
||||
|
||||
ctx, cancel := gocontext.WithCancel(git.DefaultContext)
|
||||
defer cancel()
|
||||
var stderr bytes.Buffer
|
||||
cmd := exec.Command(git.GitExecutable, service, "--stateless-rpc", h.dir)
|
||||
cmd := exec.CommandContext(ctx, git.GitExecutable, service, "--stateless-rpc", h.dir)
|
||||
cmd.Dir = h.dir
|
||||
if service == "receive-pack" {
|
||||
cmd.Env = append(os.Environ(), h.environ...)
|
||||
|
@ -472,6 +476,10 @@ func serviceRPC(h serviceHandler, service string) {
|
|||
cmd.Stdout = h.w
|
||||
cmd.Stdin = reqBody
|
||||
cmd.Stderr = &stderr
|
||||
|
||||
pid := process.GetManager().Add(fmt.Sprintf("%s %s %s [repo_path: %s]", git.GitExecutable, service, "--stateless-rpc", h.dir), cancel)
|
||||
defer process.GetManager().Remove(pid)
|
||||
|
||||
if err := cmd.Run(); err != nil {
|
||||
log.Error("Fail to serve RPC(%s): %v - %s", service, err, stderr.String())
|
||||
return
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue