summaryrefslogtreecommitdiffstats
path: root/modules/git
diff options
context:
space:
mode:
authorparnic <github@parnic.com>2022-08-06 08:13:11 -0500
committerGitHub <noreply@github.com>2022-08-06 16:13:11 +0300
commit27789908d8b06f9b856da67880d4774bd3bbddae (patch)
tree18a8dbec3e6484a8391534d7ca03b4a5dc29f696 /modules/git
parent279e4e235cd28b570e2947cc8c397280e9250440 (diff)
downloadgitea-27789908d8b06f9b856da67880d4774bd3bbddae.tar.gz
gitea-27789908d8b06f9b856da67880d4774bd3bbddae.zip
Use request timeout for git service rpc (#20689)
This enables git.Command's Run to optionally use the given context directly so its deadline will be respected. Otherwise, it falls back to the previous behavior of using the supplied timeout or a default timeout value of 360 seconds. repo's serviceRPC() calls now use the context's deadline (which is unset/unlimited) instead of the default 6-minute timeout. This means that large repo clones will no longer arbitrarily time out on the upload-pack step, and pushes can take longer than 6 minutes on the receive-pack step. Fixes #20680 Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Diffstat (limited to 'modules/git')
-rw-r--r--modules/git/command.go25
1 files changed, 17 insertions, 8 deletions
diff --git a/modules/git/command.go b/modules/git/command.go
index a1bacbb707..b24d32dbe8 100644
--- a/modules/git/command.go
+++ b/modules/git/command.go
@@ -95,14 +95,15 @@ func (c *Command) AddArguments(args ...string) *Command {
return c
}
-// RunOpts represents parameters to run the command
+// RunOpts represents parameters to run the command. If UseContextTimeout is specified, then Timeout is ignored.
type RunOpts struct {
- Env []string
- Timeout time.Duration
- Dir string
- Stdout, Stderr io.Writer
- Stdin io.Reader
- PipelineFunc func(context.Context, context.CancelFunc) error
+ Env []string
+ Timeout time.Duration
+ UseContextTimeout bool
+ Dir string
+ Stdout, Stderr io.Writer
+ Stdin io.Reader
+ PipelineFunc func(context.Context, context.CancelFunc) error
}
func commonBaseEnvs() []string {
@@ -171,7 +172,15 @@ func (c *Command) Run(opts *RunOpts) error {
desc = fmt.Sprintf("%s %s [repo_path: %s]", c.name, strings.Join(args, " "), opts.Dir)
}
- ctx, cancel, finished := process.GetManager().AddContextTimeout(c.parentContext, opts.Timeout, desc)
+ var ctx context.Context
+ var cancel context.CancelFunc
+ var finished context.CancelFunc
+
+ if opts.UseContextTimeout {
+ ctx, cancel, finished = process.GetManager().AddContext(c.parentContext, desc)
+ } else {
+ ctx, cancel, finished = process.GetManager().AddContextTimeout(c.parentContext, opts.Timeout, desc)
+ }
defer finished()
cmd := exec.CommandContext(ctx, c.name, c.args...)