Skip to content

Commit

Permalink
fix: disable relay keep alive conns, they interact poorly with suspen…
Browse files Browse the repository at this point in the history
…sion (#365)
  • Loading branch information
skabbes authored and tj committed Oct 10, 2017
1 parent a3e403b commit 653103b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 13 deletions.
15 changes: 10 additions & 5 deletions http/relay/relay.go
Expand Up @@ -34,11 +34,7 @@ var DefaultTransport http.RoundTripper = &http.Transport{
KeepAlive: 2 * time.Second,
DualStack: true,
}).DialContext,
MaxIdleConns: 0,
MaxIdleConnsPerHost: 10,
IdleConnTimeout: 5 * time.Minute,
TLSHandshakeTimeout: 2 * time.Second,
ExpectContinueTimeout: 1 * time.Second,
DisableKeepAlives: true,
}

// Proxy is a reverse proxy and sub-process monitor
Expand Down Expand Up @@ -143,6 +139,15 @@ func (p *Proxy) RoundTrip(r *http.Request) (*http.Response, error) {

retry:
attempts++
// Starting on the second attempt, we need to rewind the body if we can
// The DefaultTransport.RoundTrip will only rewind it for us in non-err scenarios
if attempts > 0 && r.Body != http.NoBody && r.Body != nil && r.GetBody != nil {
newBody, err := r.GetBody()
if err != nil {
return nil, err
}
r.Body = newBody
}

// replace host as it will change on restart
r.URL.Host = p.target.Host
Expand Down
6 changes: 4 additions & 2 deletions http/relay/relay_test.go
Expand Up @@ -98,7 +98,8 @@ func TestRelay(t *testing.T) {
"host": "example.com",
"user-agent": "tobi",
"x-forwarded-for": "192.0.2.1",
"accept-encoding": "gzip"
"accept-encoding": "gzip",
"connection": "close"
},
"url": "/echo/01BM82CJ9K1WK6EFJX8C1R4YH7/foo%20%25%20bar%20&%20baz%20=%20raz",
"body": ""
Expand All @@ -121,7 +122,8 @@ func TestRelay(t *testing.T) {
"host": "example.com",
"content-length": "14",
"x-forwarded-for": "192.0.2.1",
"accept-encoding": "gzip"
"accept-encoding": "gzip",
"connection": "close"
},
"url": "/echo/something",
"body": "Some body here"
Expand Down
6 changes: 0 additions & 6 deletions internal/proxy/request.go
Expand Up @@ -2,8 +2,6 @@ package proxy

import (
"encoding/base64"
"io"
"io/ioutil"
"net/http"
"net/url"
"strings"
Expand Down Expand Up @@ -42,10 +40,6 @@ func NewRequest(e *Input) (*http.Request, error) {
return nil, errors.Wrap(err, "creating request")
}

req.GetBody = func() (io.ReadCloser, error) {
return ioutil.NopCloser(strings.NewReader(body)), nil
}

// remote addr
req.RemoteAddr = e.RequestContext.Identity.SourceIP

Expand Down

0 comments on commit 653103b

Please sign in to comment.