Skip to content

Commit

Permalink
fix timeout not used by proxy client in fetch2 (#875)
Browse files Browse the repository at this point in the history
* fix timeout not used by proxy client in fetch2

* ran release/bumpRelease.sh 1.63.1
  • Loading branch information
ldemailly committed Dec 19, 2023
1 parent 1e2191d commit 6308314
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 23 deletions.
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!-- 1.63.0 -->
<!-- 1.63.1 -->
# Fortio

[![Awesome Go](https://fortio.org/mentioned-badge.svg)](https://github.com/avelino/awesome-go#networking)
Expand Down Expand Up @@ -60,13 +60,13 @@ You can install from source:
The [releases](https://github.com/fortio/fortio/releases) page has binaries for many OS/architecture combinations (see assets):

```shell
curl -L https://github.com/fortio/fortio/releases/download/v1.63.0/fortio-linux_amd64-1.63.0.tgz \
curl -L https://github.com/fortio/fortio/releases/download/v1.63.1/fortio-linux_amd64-1.63.1.tgz \
| sudo tar -C / -xvzpf -
# or the debian package
wget https://github.com/fortio/fortio/releases/download/v1.63.0/fortio_1.63.0_amd64.deb
dpkg -i fortio_1.63.0_amd64.deb
wget https://github.com/fortio/fortio/releases/download/v1.63.1/fortio_1.63.1_amd64.deb
dpkg -i fortio_1.63.1_amd64.deb
# or the rpm
rpm -i https://github.com/fortio/fortio/releases/download/v1.63.0/fortio-1.63.0-1.x86_64.rpm
rpm -i https://github.com/fortio/fortio/releases/download/v1.63.1/fortio-1.63.1-1.x86_64.rpm
# and more, see assets in release page
```

Expand All @@ -76,7 +76,7 @@ On a MacOS you can also install Fortio using [Homebrew](https://brew.sh/):
brew install fortio
```

On Windows, download https://github.com/fortio/fortio/releases/download/v1.63.0/fortio_win_1.63.0.zip and extract `fortio.exe` to any location, then using the Windows Command Prompt:
On Windows, download https://github.com/fortio/fortio/releases/download/v1.63.1/fortio_win_1.63.1.zip and extract `fortio.exe` to any location, then using the Windows Command Prompt:
```
fortio.exe server
```
Expand Down Expand Up @@ -130,7 +130,7 @@ Full list of command line flags (`fortio help`):
<!-- use release/updateFlags.sh to update this section -->
<pre>
<!-- USAGE_START -->
Φορτίο 1.63.0 usage:
Φορτίο 1.63.1 usage:
fortio command [flags] target
where command is one of: load (load testing), server (starts ui, rest api,
http-echo, redirect, proxies, tcp-echo, udp-echo and grpc ping servers),
Expand Down
30 changes: 20 additions & 10 deletions fhttp/http_forwarder.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,18 +260,28 @@ func (mcfg *MultiServerConfig) TeeParallelHandler(w http.ResponseWriter, r *http
}
}

func setClientOptions(client *http.Client, opts *HTTPOptions) {
log.Debugf("Setting client options to %+v", opts)
client.Timeout = opts.HTTPReqTimeOut
tls, _ := opts.TLSConfig()
client.Transport = &http.Transport{
// TODO make configurable, should be fine for now for most but extreme -c values
MaxIdleConnsPerHost: 128, // must be more than incoming parallelization; divided by number of fan out if using parallel mode
MaxIdleConns: 256,
// This avoids Accept-Encoding: gzip being added to outgoing requests when no encoding accept is specified
// yet if passed by request, it will do gzip end to end. Issue #624.
DisableCompression: true,
Proxy: http.ProxyFromEnvironment,
TLSHandshakeTimeout: DefaultHTTPOptions.HTTPReqTimeOut,
TLSClientConfig: tls,
}
}

// CreateProxyClient http client for connection reuse.
func CreateProxyClient() *http.Client {
client := &http.Client{
Transport: &http.Transport{
// TODO make configurable, should be fine for now for most but extreme -c values
MaxIdleConnsPerHost: 128, // must be more than incoming parallelization; divided by number of fan out if using parallel mode
MaxIdleConns: 256,
// This avoids Accept-Encoding: gzip being added to outgoing requests when no encoding accept is specified
// yet if passed by request, it will do gzip end to end. Issue #624.
DisableCompression: true,
},
}
log.Debugf("Creating proxy client")
client := &http.Client{}
setClientOptions(client, DefaultHTTPOptions)
return client
}

Expand Down
20 changes: 14 additions & 6 deletions fhttp/http_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package fhttp // import "fortio.org/fortio/fhttp"

import (
"bytes"
"crypto/tls"
"fmt"
"io"
"net"
Expand All @@ -29,6 +28,7 @@ import (
"sort"
"strconv"
"strings"
"sync"
"sync/atomic"
"time"

Expand Down Expand Up @@ -504,7 +504,17 @@ func SetupPPROF(mux *http.ServeMux) {

// -- Fetch er (simple http proxy) --

var proxyClient = CreateProxyClient()
var (
sharedProxyClient *http.Client
once sync.Once
)

func getProxyClient() *http.Client {
once.Do(func() {
sharedProxyClient = CreateProxyClient()
})
return sharedProxyClient
}

// FetcherHandler2 is the handler for the fetcher/proxy that supports h2 input and makes a
// new request with all headers copied (allows to test sticky routing)
Expand All @@ -531,10 +541,8 @@ func FetcherHandler2(w http.ResponseWriter, r *http.Request) {
return
}
OnBehalfOfRequest(req, r)
tr := proxyClient.Transport.(*http.Transport)
if tr.TLSClientConfig == nil || tr.TLSClientConfig.InsecureSkipVerify != opts.Insecure {
tr.TLSClientConfig = &tls.Config{InsecureSkipVerify: opts.Insecure} //nolint:gosec // as requested by the options.
}
proxyClient := getProxyClient()
setClientOptions(proxyClient, opts)
resp, err := proxyClient.Do(req)
if err != nil {
msg := fmt.Sprintf("Error for %q: %v", url, err)
Expand Down

0 comments on commit 6308314

Please sign in to comment.