]> source.dussan.org Git - gitea.git/commitdiff
fix webhook timeout bug (#15613)
authorLunny Xiao <xiaolunwen@gmail.com>
Sun, 25 Apr 2021 18:48:12 +0000 (02:48 +0800)
committerGitHub <noreply@github.com>
Sun, 25 Apr 2021 18:48:12 +0000 (21:48 +0300)
* Also fix the potential problem in httplib

modules/httplib/httplib.go
services/webhook/deliver.go

index 62f284d2e192fccf30d3a927111e55c88e0898c7..294ad0b70b6721cccad81d4f264662567e0f2104 100644 (file)
@@ -325,7 +325,7 @@ func (r *Request) getResponse() (*http.Response, error) {
                trans = &http.Transport{
                        TLSClientConfig: r.setting.TLSClientConfig,
                        Proxy:           proxy,
-                       Dial:            TimeoutDialer(r.setting.ConnectTimeout, r.setting.ReadWriteTimeout),
+                       Dial:            TimeoutDialer(r.setting.ConnectTimeout),
                }
        } else if t, ok := trans.(*http.Transport); ok {
                if t.TLSClientConfig == nil {
@@ -335,7 +335,7 @@ func (r *Request) getResponse() (*http.Response, error) {
                        t.Proxy = r.setting.Proxy
                }
                if t.Dial == nil {
-                       t.Dial = TimeoutDialer(r.setting.ConnectTimeout, r.setting.ReadWriteTimeout)
+                       t.Dial = TimeoutDialer(r.setting.ConnectTimeout)
                }
        }
 
@@ -352,6 +352,7 @@ func (r *Request) getResponse() (*http.Response, error) {
        client := &http.Client{
                Transport: trans,
                Jar:       jar,
+               Timeout:   r.setting.ReadWriteTimeout,
        }
 
        if len(r.setting.UserAgent) > 0 && len(r.req.Header.Get("User-Agent")) == 0 {
@@ -457,12 +458,12 @@ func (r *Request) Response() (*http.Response, error) {
 }
 
 // TimeoutDialer returns functions of connection dialer with timeout settings for http.Transport Dial field.
-func TimeoutDialer(cTimeout time.Duration, rwTimeout time.Duration) func(net, addr string) (c net.Conn, err error) {
+func TimeoutDialer(cTimeout time.Duration) func(net, addr string) (c net.Conn, err error) {
        return func(netw, addr string) (net.Conn, error) {
                conn, err := net.DialTimeout(netw, addr, cTimeout)
                if err != nil {
                        return nil, err
                }
-               return conn, conn.SetDeadline(time.Now().Add(rwTimeout))
+               return conn, nil
        }
 }
index 8ac7d8c1924678f1ea2e702d4152f3b3418bbe05..a417a9e846d49a2afb399451f577115dc9141d81 100644 (file)
@@ -271,14 +271,10 @@ func InitDeliverHooks() {
                        TLSClientConfig: &tls.Config{InsecureSkipVerify: setting.Webhook.SkipTLSVerify},
                        Proxy:           webhookProxy(),
                        Dial: func(netw, addr string) (net.Conn, error) {
-                               conn, err := net.DialTimeout(netw, addr, timeout)
-                               if err != nil {
-                                       return nil, err
-                               }
-
-                               return conn, conn.SetDeadline(time.Now().Add(timeout))
+                               return net.DialTimeout(netw, addr, timeout) // dial timeout
                        },
                },
+               Timeout: timeout, // request timeout
        }
 
        go graceful.GetManager().RunWithShutdownContext(DeliverHooks)