We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
When I request a api use the class below, the error occurred, I can't find the reason for a long time , so please help me , thanks !!!
go version
$ go version Output from go version go version go1.10.2 linux/amd64
i don't know
go env
$ go env GOARCH="amd64" GOBIN="" GOCACHE="/home/daiyingzong/.cache/go-build" GOEXE="" GOHOSTARCH="amd64" GOHOSTOS="linux" GOOS="linux" GOPATH="/srv/go-project" GORACE="" GOROOT="/opt/go" GOTMPDIR="" GOTOOLDIR="/opt/go/pkg/tool/linux_amd64" GCCGO="gccgo" CC="gcc" CXX="g++" CGO_ENABLED="1" 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-build343006260=/tmp/go-build -gno-record-gcc-switches"
const ( MaxIdleConns int = 200 MaxIdleConnsPerHost int = 200 IdleConnTimeout int = 90 )
func NewHttp() *HttpBase { once.Do(CreateHTTPClient) return &HttpBase{ Client: client, } }
// createHTTPClient for connection re-use func CreateHTTPClient() { client = &http.Client{ Transport: &http.Transport{ Proxy: http.ProxyFromEnvironment, DialContext: (&net.Dialer{ Timeout: 3 * time.Second, KeepAlive: 30 * time.Second, }).DialContext, MaxIdleConns: MaxIdleConns, MaxIdleConnsPerHost: MaxIdleConnsPerHost, IdleConnTimeout: 60 * time.Second, }, } }
type HttpResult struct { HttpCode int Body string }
func (h *HttpBase) HttpPost(endPoint string, payload []byte, headers map[string]string) (HttpResult, error) { ret := HttpResult{} param := bytes.NewBuffer([]byte(payload)) req, err := http.NewRequest("POST", endPoint, param) if len(headers) > 0 { for hKey, hValue := range headers { req.Header.Add(hKey, hValue) } } response, err := client.Do(req) if err != nil && response == nil { return ret, err } defer response.Body.Close()
body, err := ioutil.ReadAll(response.Body) if err != nil { return ret, err } ret.HttpCode = response.StatusCode ret.Body = string(body) return ret, nil
}
no errors
goroutine 48692 [IO wait]: internal/poll.runtime_pollWait(0x7f8201d94428, 0x72, 0xc424038760) /usr/local/go/src/runtime/netpoll.go:173 +0x57 internal/poll.(*pollDesc).wait(0xc422b2cc18, 0x72, 0xffffffffffffff00, 0xaf99e0, 0xe0d2b0) /usr/local/go/src/internal/poll/fd_poll_runtime.go:85 +0x9b internal/poll.(*pollDesc).waitRead(0xc422b2cc18, 0xc4260a5400, 0x400, 0x400) /usr/local/go/src/internal/poll/fd_poll_runtime.go:90 +0x3d internal/poll.(*FD).Read(0xc422b2cc00, 0xc4260a5400, 0x400, 0x400, 0x0, 0x0, 0x0) /usr/local/go/src/internal/poll/fd_unix.go:157 +0x17d net.(*netFD).Read(0xc422b2cc00, 0xc4260a5400, 0x400, 0x400, 0xc424038ef8, 0xc424038ef8, 0xc421c97f60) /usr/local/go/src/net/fd_unix.go:202 +0x4f net.(*conn).Read(0xc427618d48, 0xc4260a5400, 0x400, 0x400, 0x0, 0x0, 0x0) /usr/local/go/src/net/net.go:176 +0x6a crypto/tls.(*block).readFromUntil(0xc424935470, 0x7f8202254208, 0xc427618d48, 0x5, 0xc427618d48, 0xc423910600) /usr/local/go/src/crypto/tls/conn.go:493 +0x96 crypto/tls.(*Conn).readRecord(0xc42826a700, 0xab1317, 0xc42826a820, 0x453dd0) /usr/local/go/src/crypto/tls/conn.go:595 +0xe0 crypto/tls.(*Conn).Read(0xc42826a700, 0xc42ba7b000, 0x1000, 0x1000, 0x0, 0x0, 0x0) /usr/local/go/src/crypto/tls/conn.go:1156 +0x100 net/http.(*persistConn).Read(0xc42a308900, 0xc42ba7b000, 0x1000, 0x1000, 0xc424038b98, 0x403365, 0xc42bed3aa0) /usr/local/go/src/net/http/transport.go:1453 +0x136 bufio.(*Reader).fill(0xc42326a420) /usr/local/go/src/bufio/bufio.go:100 +0x11e bufio.(*Reader).Peek(0xc42326a420, 0x1, 0x0, 0x0, 0x0, 0xc4232b0e40, 0x0) /usr/local/go/src/bufio/bufio.go:132 +0x3a net/http.(*persistConn).readLoop(0xc42a308900) /usr/local/go/src/net/http/transport.go:1601 +0x185 internal/poll.(*FD).Read(0xc425803a80, 0xc4240f9000, 0x1000, 0x1000, 0x0, 0x0, 0x0) /usr/local/go/src/internal/poll/fd_unix.go:157 +0x17d net.(*netFD).Read(0xc425803a80, 0xc4240f9000, 0x1000, 0x1000, 0x453dd0, 0xc421bf1680, 0x4) /usr/local/go/src/net/fd_unix.go:202 +0x4f net.(*conn).Read(0xc4226bee50, 0xc4240f9000, 0x1000, 0x1000, 0x0, 0x0, 0x0) /usr/local/go/src/net/net.go:176 +0x6a net/http.(*persistConn).Read(0xc42236b200, 0xc4240f9000, 0x1000, 0x1000, 0xc421dceb98, 0x403365, 0xc423ba9860) /usr/local/go/src/net/http/transport.go:1453 +0x136 bufio.(*Reader).fill(0xc4276437a0) /usr/local/go/src/bufio/bufio.go:100 +0x11e bufio.(*Reader).Peek(0xc4276437a0, 0x1, 0x0, 0x0, 0x0, 0xc4238e1560, 0x0) /usr/local/go/src/bufio/bufio.go:132 +0x3a net/http.(*persistConn).readLoop(0xc42236b200) /usr/local/go/src/net/http/transport.go:1601 +0x185 created by net/http.(*Transport).dialConn /usr/local/go/src/net/http/transport.go:1237 +0x95a
goroutine 49463 [IO wait]: internal/poll.runtime_pollWait(0x7f8201ccf9e0, 0x72, 0xc428c379a8) /usr/local/go/src/runtime/netpoll.go:173 +0x57 internal/poll.(*pollDesc).wait(0xc42003f718, 0x72, 0xffffffffffffff00, 0xaf99e0, 0xe0d2b0) /usr/local/go/src/internal/poll/fd_poll_runtime.go:85 +0x9b internal/poll.(*pollDesc).waitRead(0xc42003f718, 0xc4280c0000, 0x1000, 0x1000) /usr/local/go/src/internal/poll/fd_poll_runtime.go:90 +0x3d internal/poll.(*FD).Read(0xc42003f700, 0xc4280c0000, 0x1000, 0x1000, 0x0, 0x0, 0x0) /usr/local/go/src/internal/poll/fd_unix.go:157 +0x17d net.(*netFD).Read(0xc42003f700, 0xc4280c0000, 0x1000, 0x1000, 0x453dd0, 0xc421e18780, 0x4) /usr/local/go/src/net/fd_unix.go:202 +0x4f net.(*conn).Read(0xc4239fc770, 0xc4280c0000, 0x1000, 0x1000, 0x0, 0x0, 0x0) /usr/local/go/src/net/net.go:176 +0x6a net/http.(*persistConn).Read(0xc4246feb40, 0xc4280c0000, 0x1000, 0x1000, 0xc428c37b98, 0x403365, 0xc422fa7bc0) /usr/local/go/src/net/http/transport.go:1453 +0x136 bufio.(*Reader).fill(0xc424eb28a0) /usr/local/go/src/bufio/bufio.go:100 +0x11e bufio.(*Reader).Peek(0xc424eb28a0, 0x1, 0x0, 0x0, 0x0, 0xc428c8e600, 0x0) /usr/local/go/src/bufio/bufio.go:132 +0x3a net/http.(*persistConn).readLoop(0xc4246feb40) /usr/local/go/src/net/http/transport.go:1601 +0x185 created by net/http.(*Transport).dialConn /usr/local/go/src/net/http/transport.go:1237 +0x95a
The text was updated successfully, but these errors were encountered:
Sorry, but the Go project doesn't use the issue tracker for questions. See https://golang.org/wiki/Questions.
Sorry, something went wrong.
No branches or pull requests
When I request a api use the class below, the error occurred, I can't find the reason for a long time , so please help me , thanks !!!
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
i don't know
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
const (
MaxIdleConns int = 200
MaxIdleConnsPerHost int = 200
IdleConnTimeout int = 90
)
func NewHttp() *HttpBase {
once.Do(CreateHTTPClient)
return &HttpBase{
Client: client,
}
}
// createHTTPClient for connection re-use
func CreateHTTPClient() {
client = &http.Client{
Transport: &http.Transport{
Proxy: http.ProxyFromEnvironment,
DialContext: (&net.Dialer{
Timeout: 3 * time.Second,
KeepAlive: 30 * time.Second,
}).DialContext,
MaxIdleConns: MaxIdleConns,
MaxIdleConnsPerHost: MaxIdleConnsPerHost,
IdleConnTimeout: 60 * time.Second,
},
}
}
type HttpResult struct {
HttpCode int
Body string
}
func (h *HttpBase) HttpPost(endPoint string, payload []byte, headers map[string]string) (HttpResult, error) {
ret := HttpResult{}
param := bytes.NewBuffer([]byte(payload))
req, err := http.NewRequest("POST", endPoint, param)
if len(headers) > 0 {
for hKey, hValue := range headers {
req.Header.Add(hKey, hValue)
}
}
response, err := client.Do(req)
if err != nil && response == nil {
return ret, err
}
defer response.Body.Close()
}
What did you expect to see?
no errors
What did you see instead?
goroutine 48692 [IO wait]:
internal/poll.runtime_pollWait(0x7f8201d94428, 0x72, 0xc424038760)
/usr/local/go/src/runtime/netpoll.go:173 +0x57
internal/poll.(*pollDesc).wait(0xc422b2cc18, 0x72, 0xffffffffffffff00, 0xaf99e0, 0xe0d2b0)
/usr/local/go/src/internal/poll/fd_poll_runtime.go:85 +0x9b
internal/poll.(*pollDesc).waitRead(0xc422b2cc18, 0xc4260a5400, 0x400, 0x400)
/usr/local/go/src/internal/poll/fd_poll_runtime.go:90 +0x3d
internal/poll.(*FD).Read(0xc422b2cc00, 0xc4260a5400, 0x400, 0x400, 0x0, 0x0, 0x0)
/usr/local/go/src/internal/poll/fd_unix.go:157 +0x17d
net.(*netFD).Read(0xc422b2cc00, 0xc4260a5400, 0x400, 0x400, 0xc424038ef8, 0xc424038ef8, 0xc421c97f60)
/usr/local/go/src/net/fd_unix.go:202 +0x4f
net.(*conn).Read(0xc427618d48, 0xc4260a5400, 0x400, 0x400, 0x0, 0x0, 0x0)
/usr/local/go/src/net/net.go:176 +0x6a
crypto/tls.(*block).readFromUntil(0xc424935470, 0x7f8202254208, 0xc427618d48, 0x5, 0xc427618d48, 0xc423910600)
/usr/local/go/src/crypto/tls/conn.go:493 +0x96
crypto/tls.(*Conn).readRecord(0xc42826a700, 0xab1317, 0xc42826a820, 0x453dd0)
/usr/local/go/src/crypto/tls/conn.go:595 +0xe0
crypto/tls.(*Conn).Read(0xc42826a700, 0xc42ba7b000, 0x1000, 0x1000, 0x0, 0x0, 0x0)
/usr/local/go/src/crypto/tls/conn.go:1156 +0x100
net/http.(*persistConn).Read(0xc42a308900, 0xc42ba7b000, 0x1000, 0x1000, 0xc424038b98, 0x403365, 0xc42bed3aa0)
/usr/local/go/src/net/http/transport.go:1453 +0x136
bufio.(*Reader).fill(0xc42326a420)
/usr/local/go/src/bufio/bufio.go:100 +0x11e
bufio.(*Reader).Peek(0xc42326a420, 0x1, 0x0, 0x0, 0x0, 0xc4232b0e40, 0x0)
/usr/local/go/src/bufio/bufio.go:132 +0x3a
net/http.(*persistConn).readLoop(0xc42a308900)
/usr/local/go/src/net/http/transport.go:1601 +0x185
internal/poll.(*FD).Read(0xc425803a80, 0xc4240f9000, 0x1000, 0x1000, 0x0, 0x0, 0x0)
/usr/local/go/src/internal/poll/fd_unix.go:157 +0x17d
net.(*netFD).Read(0xc425803a80, 0xc4240f9000, 0x1000, 0x1000, 0x453dd0, 0xc421bf1680, 0x4)
/usr/local/go/src/net/fd_unix.go:202 +0x4f
net.(*conn).Read(0xc4226bee50, 0xc4240f9000, 0x1000, 0x1000, 0x0, 0x0, 0x0)
/usr/local/go/src/net/net.go:176 +0x6a
net/http.(*persistConn).Read(0xc42236b200, 0xc4240f9000, 0x1000, 0x1000, 0xc421dceb98, 0x403365, 0xc423ba9860)
/usr/local/go/src/net/http/transport.go:1453 +0x136
bufio.(*Reader).fill(0xc4276437a0)
/usr/local/go/src/bufio/bufio.go:100 +0x11e
bufio.(*Reader).Peek(0xc4276437a0, 0x1, 0x0, 0x0, 0x0, 0xc4238e1560, 0x0)
/usr/local/go/src/bufio/bufio.go:132 +0x3a
net/http.(*persistConn).readLoop(0xc42236b200)
/usr/local/go/src/net/http/transport.go:1601 +0x185
created by net/http.(*Transport).dialConn
/usr/local/go/src/net/http/transport.go:1237 +0x95a
goroutine 49463 [IO wait]:
internal/poll.runtime_pollWait(0x7f8201ccf9e0, 0x72, 0xc428c379a8)
/usr/local/go/src/runtime/netpoll.go:173 +0x57
internal/poll.(*pollDesc).wait(0xc42003f718, 0x72, 0xffffffffffffff00, 0xaf99e0, 0xe0d2b0)
/usr/local/go/src/internal/poll/fd_poll_runtime.go:85 +0x9b
internal/poll.(*pollDesc).waitRead(0xc42003f718, 0xc4280c0000, 0x1000, 0x1000)
/usr/local/go/src/internal/poll/fd_poll_runtime.go:90 +0x3d
internal/poll.(*FD).Read(0xc42003f700, 0xc4280c0000, 0x1000, 0x1000, 0x0, 0x0, 0x0)
/usr/local/go/src/internal/poll/fd_unix.go:157 +0x17d
net.(*netFD).Read(0xc42003f700, 0xc4280c0000, 0x1000, 0x1000, 0x453dd0, 0xc421e18780, 0x4)
/usr/local/go/src/net/fd_unix.go:202 +0x4f
net.(*conn).Read(0xc4239fc770, 0xc4280c0000, 0x1000, 0x1000, 0x0, 0x0, 0x0)
/usr/local/go/src/net/net.go:176 +0x6a
net/http.(*persistConn).Read(0xc4246feb40, 0xc4280c0000, 0x1000, 0x1000, 0xc428c37b98, 0x403365, 0xc422fa7bc0)
/usr/local/go/src/net/http/transport.go:1453 +0x136
bufio.(*Reader).fill(0xc424eb28a0)
/usr/local/go/src/bufio/bufio.go:100 +0x11e
bufio.(*Reader).Peek(0xc424eb28a0, 0x1, 0x0, 0x0, 0x0, 0xc428c8e600, 0x0)
/usr/local/go/src/bufio/bufio.go:132 +0x3a
net/http.(*persistConn).readLoop(0xc4246feb40)
/usr/local/go/src/net/http/transport.go:1601 +0x185
created by net/http.(*Transport).dialConn
/usr/local/go/src/net/http/transport.go:1237 +0x95a
The text was updated successfully, but these errors were encountered: