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/httputil: ReverseProxy produces the error context canceled on high load #34813

Open
Refuel-ZL opened this issue Oct 10, 2019 · 3 comments

Comments

@Refuel-ZL
Copy link

commented Oct 10, 2019

What version of Go are you using (go version)?

go version go1.13.1 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
GO111MODULE="on"
GOARCH="amd64"
GOBIN="/home/zl/Desktop/mywork/GO/test01/bin"
GOCACHE="/home/zl/.cache/go-build"
GOENV="/home/zl/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/zl/Desktop/mywork/GO/test01"
GOPRIVATE=""
GOPROXY="https://goproxy.cn"
GOROOT="/home/zl/opt/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/home/zl/opt/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/dev/null"
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-build605714083=/tmp/go-build -gno-record-gcc-switches"

What did you do?

func proxy(proxy *httputil.ReverseProxy, c *gin.Context) {
	logger := log.New(os.Stderr, "", log.LstdFlags|log.Llongfile)
	proxy.ErrorLog = logger
	proxy.ErrorHandler = func(writer http.ResponseWriter, request *http.Request, e error) {
		logger.Printf("%v %v\n", request.URL.Path, e.Error()) --> context canceled
	}
	proxy.Transport = &http.Transport{
		DialContext: (&net.Dialer{
			Timeout:       90 * time.Second,
			KeepAlive:     90 * time.Second,
			FallbackDelay: -1 * time.Second,
		}).DialContext,
		ForceAttemptHTTP2:     false,
		MaxIdleConns:          100,
		IdleConnTimeout:       1 * time.Second,
		TLSHandshakeTimeout:   10 * time.Second,
		ExpectContinueTimeout: 1 * time.Second,
	}
	proxy.ServeHTTP(c.Writer, c.Request)
}

What did you see instead?

High concurrency exception:
logger.Printf("%v %v\n", request.URL.Path, e.Error()) --> context canceled

@andybons

This comment has been minimized.

Copy link
Member

commented Oct 10, 2019

What is a "high-concurrency exception"?

@Refuel-ZL

This comment has been minimized.

Copy link
Author

commented Oct 11, 2019

2w QPS touch off “context canceled”

@odeke-em

This comment has been minimized.

Copy link
Member

commented Oct 11, 2019

@Refuel-ZL thank you for filing this issue and welcome to the Go project!

2w QPS touch off “context canceled”

What does that "2w" "touch off" mean? Could you please be more specific and also it would be nice if you could try to simulate/reproduce this issue for example using http://github.com/rakyll/hey or Apache bench or whichever load generator you'd like? Thank you!

@odeke-em odeke-em changed the title httputil.ReverseProxy The error context canceled net/http/httputil: ReverseProxy produces the error context canceled on high load Oct 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.