Description
Please answer these questions before submitting your issue. Thanks!
What version of Go are you using (go version
)?
go version go1.9.2 darwin/amd64
Does this issue reproduce with the latest release?
I suppose it is the last release
What operating system and processor architecture are you using (go env
)?
GOARCH="amd64"
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
What did you do?
package main
var indice = 0
var thnb = 0
func Hello(w http.ResponseWriter, r *http.Request) {
indice++
thnb ++
var i = indice
r.ParseForm()
if indice == 1 {
time.Sleep(40 * time.Second)
} else {
indice = 0
}
m := fmt.Sprintf("Hello from Golang with indice: %d, thread: %d", i, thnb)
json.NewEncoder(w).Encode(m)
}
func main() {
http.HandleFunc("/hello", Hello)
s := &http.Server{
Addr: ":8000",
ReadTimeout: 30 * time.Second,
WriteTimeout: 30 * time.Second,
//MaxHeaderBytes: 1 << 20,
}
}
What did you expect to see?
I expected that the first request doesn't block the second one launch at the same time.
What did you see instead?
The first request block the second one during its sleep process when I invoke the url : http://127.0.0.1/hello
But if I add parameters to the URL like:
- http://127.0.0.1/hello?param=1 for the first request
- http://127.0.0.1/hello?param=2 for the second one
then the behavior is what I was expecting.
I don't understand what's the difference and why the handleFunc blocks.
Thanks for your answer