From bd08c91889a46ca586dd6380ad5140619cacbb3e Mon Sep 17 00:00:00 2001 From: Umputun Date: Fri, 9 Apr 2021 20:54:02 -0500 Subject: [PATCH] don't use default transport for proxy, causing race with tests --- app/proxy/health_test.go | 2 +- app/proxy/proxy.go | 14 ++++++++++++-- app/proxy/proxy_test.go | 3 ++- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/app/proxy/health_test.go b/app/proxy/health_test.go index 2574b97..8940705 100644 --- a/app/proxy/health_test.go +++ b/app/proxy/health_test.go @@ -53,7 +53,7 @@ func TestHttp_healthHandler(t *testing.T) { go func() { _ = h.Run(ctx) }() - time.Sleep(10 * time.Millisecond) + time.Sleep(20 * time.Millisecond) client := http.Client{} req, err := http.NewRequest("GET", "http://127.0.0.1:"+strconv.Itoa(port)+"/health", nil) diff --git a/app/proxy/proxy.go b/app/proxy/proxy.go index 0c44146..1dbc8b3 100644 --- a/app/proxy/proxy.go +++ b/app/proxy/proxy.go @@ -141,8 +141,18 @@ func (h *Http) proxyHandler() http.HandlerFunc { }, } - reverseProxy.Transport = http.DefaultTransport - reverseProxy.Transport.(*http.Transport).ResponseHeaderTimeout = h.TimeOut + reverseProxy.Transport = &http.Transport{ + ResponseHeaderTimeout: h.TimeOut, + DialContext: (&net.Dialer{ + Timeout: 30 * time.Second, + KeepAlive: 30 * time.Second, + }).DialContext, + ForceAttemptHTTP2: true, + MaxIdleConns: 100, + IdleConnTimeout: 90 * time.Second, + TLSHandshakeTimeout: 10 * time.Second, + ExpectContinueTimeout: 1 * time.Second, + } // default assetsHandler disabled, returns error on missing matches assetsHandler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { diff --git a/app/proxy/proxy_test.go b/app/proxy/proxy_test.go index e46890b..97f572e 100644 --- a/app/proxy/proxy_test.go +++ b/app/proxy/proxy_test.go @@ -42,6 +42,7 @@ func TestHttp_Do(t *testing.T) { _ = svc.Run(context.Background()) }() + time.Sleep(10 * time.Millisecond) h.Matcher = svc go func() { _ = h.Run(ctx) @@ -113,7 +114,7 @@ func TestHttp_DoWithAssets(t *testing.T) { go func() { _ = svc.Run(context.Background()) }() - + time.Sleep(10 * time.Millisecond) h.Matcher = svc go func() { _ = h.Run(ctx)