go - golang http server does not accept post large data -


at current time try use golang http server , compile code:

    package main  import (     "io"     "net/http"     "time" )  func hello(w http.responsewriter, r *http.request) {     r.parseform()     io.writestring(w, "hello world!") }  var mux map[string]func(http.responsewriter, *http.request)  func main() {     server := http.server{         addr:           ":8000",         maxheaderbytes: 30000000,         readtimeout:    10 * time.second,         writetimeout:   10 * time.second,         handler:        &myhandler{},     }      mux = make(map[string]func(http.responsewriter, *http.request))     mux["/"] = hello      server.listenandserve() }  type myhandler struct{}  func (*myhandler) servehttp(w http.responsewriter, r *http.request) {     if h, ok := mux[r.url.string()]; ok {         h(w, r)         return     }      io.writestring(w, "my server: "+r.url.string()) } 

runs , send test data via apache bench

ab.exe -c 30 -n 1000 -p esserver.exe -t application/octet-stream http://localhost:8000/  

it's working excelent small files esserver.exe has size 8mb , i'm receiving next error "apr_socket_recv: existing connection forcibly closed remote host. (730054)."

what problem may happens?

you're not reading request body, each request going block once buffers filled. need read request in full or forcibly disconnect client avoid request hanging , consuming resources.

at minimum, can

io.copy(ioutil.discard, r.body) 

Comments