Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

net/http: unexpected timeout while waiting for connection #34595

Closed
yuanshuli11 opened this issue Sep 29, 2019 · 3 comments
Closed

net/http: unexpected timeout while waiting for connection #34595

yuanshuli11 opened this issue Sep 29, 2019 · 3 comments

Comments

@yuanshuli11
Copy link

yuanshuli11 commented Sep 29, 2019

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

@yuanshuli11
Copy link
Author

yuanshuli11 commented Sep 29, 2019

using Benchmark like this
go test -bench=. -count 100000 > test.log
few minutes later,you can see error like these.

error Get http://10.33.108.39:11222/index.php: net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers)
error Get http://10.33.108.39:11222/index.php: net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers)
error Get http://10.33.108.39:11222/index.php: net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers)

@smasher164 smasher164 changed the title Unexpected Error: net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers) net/http: unexpected timeout while waiting for connection Sep 29, 2019
@yuanshuli11
Copy link
Author

yuanshuli11 commented Sep 30, 2019

You can reproduce using my code.
About few minutes later,you may see error in log ,such as net http://10.33.108.39:11222/index.php: net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers).

@bcmills
Copy link
Contributor

bcmills commented Sep 30, 2019

This issue seems to be a question about how to use Go, rather than a feature request or defect report about the Go language and/or toolchain.

We have decided that our experiment to allow questions on the issue tracker has not had the outcome we desired, so I am closing this issue. I'm sorry that we can't answer your question here.

There are many other methods to get help if you're still looking for answers:

Thanks

@bcmills bcmills closed this as completed Sep 30, 2019
@golang golang locked and limited conversation to collaborators Sep 29, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants