Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

net/http: ReverseProxy always trigger http.Server.ReadTimeout #18796

Closed
L-P opened this issue Jan 26, 2017 · 2 comments

Comments

Projects
None yet
3 participants
@L-P
Copy link

commented Jan 26, 2017

What version of Go are you using (go version)?

go version go1.7.4 linux/amd64

What operating system and processor architecture are you using (go env)?

GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/lpeltier/Documents/go"
GORACE=""
GOROOT="/opt/go"
GOTOOLDIR="/opt/go/pkg/tool/linux_amd64"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build343847435=/tmp/go-build -gno-record-gcc-switches"
CXX="g++"
CGO_ENABLED="1"

What did you do?

I have a http.ReverseProxy as the handler of a http.Server
configured with a ReadTimeout, and serving a large file.

package main

import (
	"net/http"
	"net/http/httputil"
	"net/url"
	"time"
)

func main() {
	server := &http.Server{
		Addr:        ":1990",
		ReadTimeout: 1 * time.Second,
		Handler:     newProxy(),
	}
	server.ListenAndServe()
}

func newProxy() *httputil.ReverseProxy {
	director := func(req *http.Request) {
		req.URL, _ = url.Parse("http://releases.ubuntu.com/16.04/ubuntu-16.04.1-desktop-amd64.iso")
		req.Host = req.URL.Host
	}

	return &httputil.ReverseProxy{
		Director: director,
	}
}

What did you expect to see?

I expect the proxy to serve the whole file.

What did you see instead?

The ReadTimeout always trigger and closes the connection even though
the full request has been read and the response is being sent to the client.

$ curl localhost:1990 > /dev/null
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0 1443M    0  9.7M    0     0   9.7M      0  0:02:27  0:00:01  0:02:26  9.7M
curl: (18) transfer closed with 1503043678 bytes remaining to read

Time Spent equals my ReadTimeout.

@ALTree

This comment has been minimized.

Copy link
Member

commented Jan 26, 2017

I can't reproduce the problem on go1.8.

I believe this is a dup of #18447, which was fixed on tip by ecac827.

@ALTree ALTree changed the title ReverseProxy always trigger http.Server.ReadTimeout net/http: ReverseProxy always trigger http.Server.ReadTimeout Jan 26, 2017

@L-P

This comment has been minimized.

Copy link
Author

commented Jan 26, 2017

Can't reproduce on go version go1.8rc2 linux/amd64 either. Thanks.

@L-P L-P closed this Jan 26, 2017

@golang golang locked and limited conversation to collaborators Jan 26, 2018

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
You can’t perform that action at this time.