Closed as not planned
Description
What version of Go are you using (go version
)?
$ go version go version go1.21.1 linux/amd64
Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (go env
)?
go env
Output
$ go env GO111MODULE='' GOARCH='amd64' GOBIN='' GOEXE='' GOEXPERIMENT='' GOFLAGS='' GOHOSTARCH='amd64' GOHOSTOS='linux' GOINSECURE='' GONOPROXY='' GONOSUMDB='' GOOS='linux' GOPRIVATE='' GOPROXY='https://proxy.golang.org,direct' GOROOT='/opt/go' GOSUMDB='sum.golang.org' GOTMPDIR='' GOTOOLCHAIN='auto' GOTOOLDIR='/opt/go/pkg/tool/linux_amd64' GOVCS='' GOVERSION='go1.21.1' GCCGO='/usr/bin/gccgo' GOAMD64='v1' AR='ar' CC='gcc' CXX='g++' CGO_ENABLED='1' GOMOD='/dev/null' GOWORK='' CGO_CFLAGS='-O2 -g' CGO_CPPFLAGS='' CGO_CXXFLAGS='-O2 -g' CGO_FFLAGS='-O2 -g' CGO_LDFLAGS='-O2 -g' PKG_CONFIG='pkg-config' GOGCCFLAGS='-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build2527636589=/tmp/go-build -gno-record-gcc-switches'
What did you do?
server.go code
package main import ( "fmt" "net/http" ) type handler struct { } func (h *handler) ServeHTTP (w http.ResponseWriter, r *http.Request) { go func() { ctx := r.Context() <- ctx.Done() log(ctx.Err()) }() log(r.Method + " " + r.RequestURI + " " + r.Proto) d := w.Header() d.Set("Server", "foo/1.0") if origin := r.Header.Get("Origin"); "" != origin { d.Set("Access-Control-Allow-Origin", origin) } switch r.Method { case "PUT": w.WriteHeader(http.StatusRequestEntityTooLarge) case "OPTIONS": d.Set("Access-Control-Allow-Methods", "OPTIONS, GET, HEAD, PUT, DELETE") d.Set("Access-Control-Allow-Headers", "Content-Type") d.Set("Access-Control-Allow-Max-Age", "86400") d.Set("Access-Control-Allow-Credentials", "true") w.WriteHeader(http.StatusNoContent) } log("Done") } func log (i any) { fmt.Printf("%v\n", i) } func main () { srv := &http.Server{ Addr: ":8888", Handler: &handler{}, } log(srv.ListenAndServe()) }
I do (file size 10MB)
$ go run server.go $ wget -t1 -qSO - --method=PUT --body-file=10MB.mp4 'http://localhost:8888/'
server log
PUT / HTTP/1.1 Done context canceled
clent log empty and connection reset
$ echo $? 4
man wget (4 = Network failure.)
ok, I do (file size 1MB)
$ wget -t1 -qSO - --method=PUT --body-file=1MB.mp3 'http://localhost:8888/'
client log now
HTTP/1.1 413 Request Entity Too Large Server: foo/1.0 Date: Sat, 09 Sep 2023 07:44:06 GMT Content-Length: 0
What did you expect to see?
expected behavior, client receives response
What did you see instead?
client does not receive a response, and connection is closed
Additionally, when using encryption and HTTP 2, the error does not recur; it seems that the context is canceled due to a timeout and the client does not have time to read the response when the header Content-Length contains a sufficiently large value. And, if the request is made from the browser, the browser sends another repeat request
Metadata
Metadata
Assignees
Labels
No labels