Skip to content

Commit 3d5bb3e

Browse files
authored
fix webhook timeout bug (#15613)
* Also fix the potential problem in httplib
1 parent 6ea6e2b commit 3d5bb3e

File tree

2 files changed

+7
-10
lines changed

2 files changed

+7
-10
lines changed

modules/httplib/httplib.go

+5-4
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ func (r *Request) getResponse() (*http.Response, error) {
325325
trans = &http.Transport{
326326
TLSClientConfig: r.setting.TLSClientConfig,
327327
Proxy: proxy,
328-
Dial: TimeoutDialer(r.setting.ConnectTimeout, r.setting.ReadWriteTimeout),
328+
Dial: TimeoutDialer(r.setting.ConnectTimeout),
329329
}
330330
} else if t, ok := trans.(*http.Transport); ok {
331331
if t.TLSClientConfig == nil {
@@ -335,7 +335,7 @@ func (r *Request) getResponse() (*http.Response, error) {
335335
t.Proxy = r.setting.Proxy
336336
}
337337
if t.Dial == nil {
338-
t.Dial = TimeoutDialer(r.setting.ConnectTimeout, r.setting.ReadWriteTimeout)
338+
t.Dial = TimeoutDialer(r.setting.ConnectTimeout)
339339
}
340340
}
341341

@@ -352,6 +352,7 @@ func (r *Request) getResponse() (*http.Response, error) {
352352
client := &http.Client{
353353
Transport: trans,
354354
Jar: jar,
355+
Timeout: r.setting.ReadWriteTimeout,
355356
}
356357

357358
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) {
457458
}
458459

459460
// TimeoutDialer returns functions of connection dialer with timeout settings for http.Transport Dial field.
460-
func TimeoutDialer(cTimeout time.Duration, rwTimeout time.Duration) func(net, addr string) (c net.Conn, err error) {
461+
func TimeoutDialer(cTimeout time.Duration) func(net, addr string) (c net.Conn, err error) {
461462
return func(netw, addr string) (net.Conn, error) {
462463
conn, err := net.DialTimeout(netw, addr, cTimeout)
463464
if err != nil {
464465
return nil, err
465466
}
466-
return conn, conn.SetDeadline(time.Now().Add(rwTimeout))
467+
return conn, nil
467468
}
468469
}

services/webhook/deliver.go

+2-6
Original file line numberDiff line numberDiff line change
@@ -271,14 +271,10 @@ func InitDeliverHooks() {
271271
TLSClientConfig: &tls.Config{InsecureSkipVerify: setting.Webhook.SkipTLSVerify},
272272
Proxy: webhookProxy(),
273273
Dial: func(netw, addr string) (net.Conn, error) {
274-
conn, err := net.DialTimeout(netw, addr, timeout)
275-
if err != nil {
276-
return nil, err
277-
}
278-
279-
return conn, conn.SetDeadline(time.Now().Add(timeout))
274+
return net.DialTimeout(netw, addr, timeout) // dial timeout
280275
},
281276
},
277+
Timeout: timeout, // request timeout
282278
}
283279

284280
go graceful.GetManager().RunWithShutdownContext(DeliverHooks)

0 commit comments

Comments
 (0)