aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKai Leonhardt <8343141+Mik4sa@users.noreply.github.com>2025-03-21 20:52:14 +0100
committerGitHub <noreply@github.com>2025-03-21 12:52:14 -0700
commitb5d2e31d6d7d96e1884f1aaed43ca7b74cc591db (patch)
tree89777fb1f7f9740620aa6b343b145b6fbceeb51c
parentb956cee06f462c4f34a7911351b7c878ce890725 (diff)
downloadgitea-b5d2e31d6d7d96e1884f1aaed43ca7b74cc591db.tar.gz
gitea-b5d2e31d6d7d96e1884f1aaed43ca7b74cc591db.zip
Drop timeout for requests made to the internal hook api (#33947)
This change targets https://github.com/go-gitea/gitea/issues/32663 We drop the hardcoded timeout of 60 seconds for requests to the internal hook api. With this change the timeout is completly removed. --------- Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
-rw-r--r--modules/private/hook.go25
1 files changed, 14 insertions, 11 deletions
diff --git a/modules/private/hook.go b/modules/private/hook.go
index 87d6549f9c..215996b9b9 100644
--- a/modules/private/hook.go
+++ b/modules/private/hook.go
@@ -7,9 +7,9 @@ import (
"context"
"fmt"
"net/url"
- "time"
"code.gitea.io/gitea/modules/git"
+ "code.gitea.io/gitea/modules/httplib"
"code.gitea.io/gitea/modules/repository"
"code.gitea.io/gitea/modules/setting"
)
@@ -82,29 +82,32 @@ type HookProcReceiveRefResult struct {
HeadBranch string
}
+func newInternalRequestAPIForHooks(ctx context.Context, hookName, ownerName, repoName string, opts HookOptions) *httplib.Request {
+ reqURL := setting.LocalURL + fmt.Sprintf("api/internal/hook/%s/%s/%s", hookName, url.PathEscape(ownerName), url.PathEscape(repoName))
+ req := newInternalRequestAPI(ctx, reqURL, "POST", opts)
+ // This "timeout" applies to http.Client's timeout: A Timeout of zero means no timeout.
+ // This "timeout" was previously set to `time.Duration(60+len(opts.OldCommitIDs))` seconds, but it caused unnecessary timeout failures.
+ // It should be good enough to remove the client side timeout, only respect the "ctx" and server side timeout.
+ req.SetReadWriteTimeout(0)
+ return req
+}
+
// HookPreReceive check whether the provided commits are allowed
func HookPreReceive(ctx context.Context, ownerName, repoName string, opts HookOptions) ResponseExtra {
- reqURL := setting.LocalURL + fmt.Sprintf("api/internal/hook/pre-receive/%s/%s", url.PathEscape(ownerName), url.PathEscape(repoName))
- req := newInternalRequestAPI(ctx, reqURL, "POST", opts)
- req.SetReadWriteTimeout(time.Duration(60+len(opts.OldCommitIDs)) * time.Second)
+ req := newInternalRequestAPIForHooks(ctx, "pre-receive", ownerName, repoName, opts)
_, extra := requestJSONResp(req, &ResponseText{})
return extra
}
// HookPostReceive updates services and users
func HookPostReceive(ctx context.Context, ownerName, repoName string, opts HookOptions) (*HookPostReceiveResult, ResponseExtra) {
- reqURL := setting.LocalURL + fmt.Sprintf("api/internal/hook/post-receive/%s/%s", url.PathEscape(ownerName), url.PathEscape(repoName))
- req := newInternalRequestAPI(ctx, reqURL, "POST", opts)
- req.SetReadWriteTimeout(time.Duration(60+len(opts.OldCommitIDs)) * time.Second)
+ req := newInternalRequestAPIForHooks(ctx, "post-receive", ownerName, repoName, opts)
return requestJSONResp(req, &HookPostReceiveResult{})
}
// HookProcReceive proc-receive hook
func HookProcReceive(ctx context.Context, ownerName, repoName string, opts HookOptions) (*HookProcReceiveResult, ResponseExtra) {
- reqURL := setting.LocalURL + fmt.Sprintf("api/internal/hook/proc-receive/%s/%s", url.PathEscape(ownerName), url.PathEscape(repoName))
-
- req := newInternalRequestAPI(ctx, reqURL, "POST", opts)
- req.SetReadWriteTimeout(time.Duration(60+len(opts.OldCommitIDs)) * time.Second)
+ req := newInternalRequestAPIForHooks(ctx, "proc-receive", ownerName, repoName, opts)
return requestJSONResp(req, &HookProcReceiveResult{})
}