Closed
Description
What version of Go are you using (go version
)?
$ go version go version go1.12.5 linux/amd64
Does this issue reproduce with the latest release?
no sure.
Only reproduce on my version
What operating system and processor architecture are you using (go env
)?
go env
Output
$ go env GOARCH="amd64" GOBIN="/usr/local/go/bin" GOCACHE="/home/yuan/.cache/go-build" GOEXE="" GOFLAGS="" GOHOSTARCH="amd64" GOHOSTOS="linux" GOOS="linux" GOPATH="/data0/www/gopath" GOPROXY="" GORACE="" GOROOT="/usr/local/go" GOTMPDIR="" GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64" GCCGO="gccgo" CC="gcc" CXX="g++" CGO_ENABLED="1" GOMOD="" CGO_CFLAGS="-g -O2" CGO_CPPFLAGS="" CGO_CXXFLAGS="-g -O2" CGO_FFLAGS="-g -O2" CGO_LDFLAGS="-g -O2" PKG_CONFIG="pkg-config" GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build422863565=/tmp/go-build -gno-record-gcc-switches"
What did you do?
package httptest import ( "fmt" "io/ioutil" "net/http" "sync" "testing" "time" ) var client *http.Client = &http.Client{ Timeout: 500 * time.Millisecond, Transport: &http.Transport{ DisableKeepAlives: true, MaxIdleConnsPerHost: -1, }, } func Benchmark_List(b *testing.B) { var ( wg sync.WaitGroup maxParallel int = 50 parallelChan chan bool = make(chan bool, maxParallel) ) b.ResetTimer() for i := 0; i < b.N; i++ { parallelChan <- true wg.Add(1) go func() { defer func() { wg.Done() <-parallelChan }() testHttp2() }() } wg.Wait() } func testHttp2() { req, _ := http.NewRequest("GET", "http://10.33.108.39:11222/index.php", nil) resp, err := client.Do(req) if err != nil { fmt.Println("error", err) return } _, err = ioutil.ReadAll(resp.Body) if err != nil { return } defer resp.Body.Close() fmt.Println("success") }
What did you expect to see?
When I use ApacheBench to express the server 127.0.0.1:8080
ab -c 30 -n 10000000 -k http://127.0.0.1:8080
I think my code is ok。No bug.
What did you see instead?
But about every 3-4 minute, I saw the error in my log
net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers)
my machine is ok.and this is my netstat.
LAST_ACK 2
CLOSE_WAIT 7
ESTABLISHED 108
SYN_SENT 3
TIME_WAIT 43