ApacheBench仅使用“ -race”标志从Go服务器获取“对等连接重置”

I have a minimal Go HTTP server (code below). When I start the server with go run server.go and then fire off 5000 concurrent requests using

ab -c 5000 -n 5000 http://localhost:8080/

everything works as expected. However, if I start my server with the race detector flag:

go run -race server.go

then I get an issue running ApacheBench even with only 1000 concurrent requests:

apr_socket_recv: Connection reset by peer (54)

Interestingly, my Go server doesn't crash or print any error messages, and is able to continue receiving new requests. This suggests that the problem is not the Go process running out of memory because of the "-race" burden.

Additional details:

  • I'm running Go 1.10 on a Mac
  • ab -V tells me I'm using Version 2.3 of ab (default shipment with Macbook, and it looks like ab has been dropped from brew).
  • If I run ab with the -r flag so that it doesn't exit right away, I get the output: Test aborted after 10 failures. So it seems like my Go server must be dropping connections rather than queueing them up...

Go server code:

package main

import (
    "log"
    "net/http"
)

func handler(w http.ResponseWriter, r *http.Request) {
    log.Printf("got one
")
}

func main() {
    http.HandleFunc("/", handler)
    log.Fatal(http.ListenAndServe(":8080", nil))
}

ulimit settings:

$ ulimit -a
core file size          (blocks, -c) 0
data seg size           (kbytes, -d) unlimited
file size               (blocks, -f) unlimited
max locked memory       (kbytes, -l) unlimited
max memory size         (kbytes, -m) unlimited
open files                      (-n) 4864
pipe size            (512 bytes, -p) 1
stack size              (kbytes, -s) 8192
cpu time               (seconds, -t) unlimited
max user processes              (-u) 709
virtual memory          (kbytes, -v) unlimited