Description
Please answer these questions before submitting your issue. Thanks!
What version of Go are you using (go version
)?
go version go1.8.3 darwin/amd64
What operating system and processor architecture are you using (go env
)?
GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/uwe/dev/go"
GORACE=""
GOROOT="/usr/local/Cellar/go/1.8.3/libexec"
GOTOOLDIR="/usr/local/Cellar/go/1.8.3/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/p2/0p6x8w350vqgpvfby6wnxnhc0000gn/T/go-build935868292=/tmp/go-build -gno-record-gcc-switches -fno-common"
CXX="clang++"
CGO_ENABLED="1"
PKG_CONFIG="pkg-config"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
What did you do?
https://play.golang.org/p/pwjZmMKleR
Create a HTTP server with a WriteTimeout = 1 * time.Second
and a HTTPHandler
with an artificial time.Sleep(2 * time.Second)
and then writing out some bytes. Then start the server and run a request against this handler.
What did you expect to see?
Writing a response after hitting WriteTimeout
should at least do one out of the two options:
- Return an error for
n, err := w.Write()
- Log a message to
http.Server.ErrorLog
(1) would indicate that no more bytes can be written, e.g. because the connection was closed.
(2) would be similar to w.conn.server.logf("http: multiple response.WriteHeader calls")
, e.g. w.conn.server.logf("http: write attempt after write timeout")
.
What did you see instead?
Neither (1) nor (2) happened.
This was confusing as I saw in my http logging middleware that response bytes have been written, but I did not understand to where/which connection; which was hard to debug.
While trying to understand how WriteTimeout
works it seems that the http server's ResponseWriter
is not aware of the consequences. But I would like to discuss if there are options to improve the situation/inform the user.
An example of the observed consequences with WriteTimeout
set to 3 * time.Second
on e.g. Heroku:
Aug 07 12:16:48 {"level":"info","ts":1502108208.0430696,"caller":"middleware/logger.go:91","msg":"Outgoing response","request_id":"a8fe82a0-c212-4527-9cae-06e38cf46d49","status":200,"latency":9.043189693,"bytes_out":97}
Aug 07 12:16:48 heroku/router: at=error code=H13 desc="Connection closed without response" method=GET path="/foo" host=bar request_id=a8fe82a0-c212-4527-9cae-06e38cf46d49 fwd="54.216.3.69" dyno=web.1 connect=0ms service=9044ms status=503 bytes=0 protocol=https