-
Notifications
You must be signed in to change notification settings - Fork 18.8k
Description
What version of Go are you using (go version)?
$ go version go version go1.18 darwin/arm64
Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (go env)?
GO111MODULE="on"
GOARCH="arm64"
GOBIN="/Library/WebServer/Documents/yuebai/bin"
GOCACHE="/Users/zhaozuowu/Library/Caches/go-build"
GOENV="/Users/zhaozuowu/Library/Application Support/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="arm64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/zhaozuowu/.gvm/pkgsets/go1.18/global/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/zhaozuowu/.gvm/pkgsets/go1.18/global"
GOPRIVATE=""
GOPROXY="https://goproxy.cn"
GOROOT="/Users/zhaozuowu/.gvm/gos/go1.18"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/Users/zhaozuowu/.gvm/gos/go1.18/pkg/tool/darwin_arm64"
GOVCS=""
GOVERSION="go1.18"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Library/WebServer/Documents/yuebai/src/leak/go.mod"
GOWORK=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/pl/tz0tvgq578x0zqh5q6bd41jh0000gn/T/go-build1005337739=/tmp/go-build -gno-record-gcc-switches -fno-common"
go env Output
$ go env
What did you do?
I launched an http get request for an https redirect short link, expecting to get a long redirected connection. As a result, the http client class library directly raised an error and returned remote error: tls: internal error, the service will generate a large number of Ctrip leaks at a moment, the following is used to demonstrate and reproduce the error:
package main
import (
"crypto/tls"
"fmt"
"io/ioutil"
"net"
"net/http"
"net/url"
"time"
)
var DefaultTransports *http.Transport
func init() {
DefaultTransports = http.DefaultTransport.(*http.Transport).Clone()
DefaultTransports.MaxIdleConns = 0
DefaultTransports.MaxIdleConnsPerHost = 200
//DefaultTransports.MaxConnsPerHost = 200
DefaultTransports.IdleConnTimeout = 90 * time.Second
DefaultTransports.TLSClientConfig = &tls.Config{InsecureSkipVerify: true}
//DefaultTransports.DisableKeepAlives = true
DefaultTransports.DialContext = (&net.Dialer{
Timeout: time.Second * 3,
KeepAlive: time.Second * 15,
}).DialContext
}
func main() {
location, err := GetHeaderLocation("https://p.pinduoduo.com/TGvnEO7z")
if err != nil {
switch err.(type) {
case *url.Error:
urlErr := err.(*url.Error)
if urlErr != nil && urlErr.URL != "" {
location = urlErr.URL
}
default:
}
}
fmt.Println(location, err)
}
func GetHeaderLocation(url string) (string, error) {
req, err := http.NewRequest("GET", url, nil)
if err != nil {
//logger.Warnf("http get::url:%s ,request:%+v err:%v", urlStr, params, err)
return "", err
}
client := &http.Client{
Timeout: 3 * time.Second,
Transport: DefaultTransports,
}
resp, err := client.Do(req)
if err != nil {
//logger.Warnf("http get::url:%s ,request:%+v err:%v", urlStr, params, err)
return "", err
}
defer resp.Body.Close()
_, _ = ioutil.ReadAll(resp.Body)
if resp.Request != nil && resp.Request.Response != nil {
return resp.Request.Response.Header.Get("Location"), nil
}
return "", nil
}
What did you expect to see?
I expect to return a correct http response, not tls:internal error, and not reference (*url.Error). Urls will cause Ctrip to jam, which will lead to memory leaks