Add timeouts to reverse proxy and to http server, reduce timeout in config
This commit is contained in:
@@ -6,7 +6,7 @@ proto = http
|
||||
port = 9980
|
||||
|
||||
; timeout for upstream connection
|
||||
timeout = 30
|
||||
timeout = 5
|
||||
|
||||
; loglevel - info or debug, info is what you want
|
||||
loglevel = debug
|
||||
|
||||
13
main.go
13
main.go
@@ -4,6 +4,7 @@ import (
|
||||
"fmt"
|
||||
"html"
|
||||
"math/rand"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/http/httputil"
|
||||
"net/url"
|
||||
@@ -227,6 +228,13 @@ func joyproxyHandler(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
joyproxy := httputil.NewSingleHostReverseProxy(target)
|
||||
joyproxy.Transport = &http.Transport{
|
||||
Dial: (&net.Dialer{
|
||||
Timeout: time.Duration(cfg.timeout) * time.Second,
|
||||
KeepAlive: time.Duration(cfg.timeout) * time.Second,
|
||||
}).Dial,
|
||||
TLSHandshakeTimeout: time.Duration(cfg.timeout) * time.Second,
|
||||
}
|
||||
joyproxy.ServeHTTP(w, dlReq)
|
||||
}
|
||||
|
||||
@@ -307,7 +315,10 @@ func main() {
|
||||
// timeout and sits here forever.
|
||||
server := &http.Server{
|
||||
Addr: cfg.port,
|
||||
ReadHeaderTimeout: 3 * time.Second,
|
||||
ReadHeaderTimeout: time.Duration(cfg.timeout) * time.Second,
|
||||
ReadTimeout: time.Duration(cfg.timeout) * time.Second,
|
||||
WriteTimeout: time.Duration(cfg.timeout) * time.Second,
|
||||
IdleTimeout: time.Duration(cfg.timeout) * time.Second,
|
||||
}
|
||||
|
||||
log.Warn(server.ListenAndServe())
|
||||
|
||||
Reference in New Issue
Block a user