Closed
Description
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
.