Closed
Description
What version of Go are you using (go version
)?
1.13.4 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
What did you do?
I have a piece of code to implement a simple HTTP server with golang.
package main
import (
"io"
"log"
"net/http"
"net"
"golang.org/x/net/netutil"
)
func main() {
helloHandler := func(w http.ResponseWriter, req *http.Request) {
io.WriteString(w, "Hello, world!\n")
}
mux := http.NewServeMux()
handler := http.HandlerFunc(helloHandler)
mux.Handle("/hello", handler)
connectionCount := 20
l, err := net.Listen("tcp", ":8000")
if err != nil {
log.Fatalf("Listen: %v", err)
}
defer l.Close()
l = netutil.LimitListener(l, connectionCount)
log.Fatal(http.Serve(l, mux))
}
Using wrk to test the connection limitation.
./wrk -t4 -c100 -d30s 'http://127.0.0.1:8000/hello'
What did you expect to see?
The number of established tcp connection should be limited to 20
What did you see instead?
netstat -an | grep 8000 | wc -l
The output is 102. It looks like the LimitListener does not make server reject the new incoming TCP connections when connection number is more than 20.