golang open files 是keepalives的问题.
This commit is contained in:
parent
823e5e0bcf
commit
a0d8830242
13
session.go
13
session.go
|
@ -178,6 +178,8 @@ func NewSession() *Session {
|
||||||
client := &http.Client{}
|
client := &http.Client{}
|
||||||
transport := &http.Transport{DisableCompression: true, DisableKeepAlives: true}
|
transport := &http.Transport{DisableCompression: true, DisableKeepAlives: true}
|
||||||
|
|
||||||
|
EnsureTransporterFinalized(transport)
|
||||||
|
|
||||||
client.Transport = transport
|
client.Transport = transport
|
||||||
cjar, err := cookiejar.New(&cookiejar.Options{PublicSuffixList: publicsuffix.List})
|
cjar, err := cookiejar.New(&cookiejar.Options{PublicSuffixList: publicsuffix.List})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -361,16 +363,15 @@ func (ses *Session) Delete(url string) *Workflow {
|
||||||
return wf
|
return wf
|
||||||
}
|
}
|
||||||
|
|
||||||
// CloseIdleConnections closes the idle connections that a session client may make use of
|
// // CloseIdleConnections closes the idle connections that a session client may make use of
|
||||||
// 从levigross/grequests 借鉴
|
// // 从levigross/grequests 借鉴
|
||||||
func (ses *Session) CloseIdleConnections() {
|
// func (ses *Session) CloseIdleConnections() {
|
||||||
ses.client.Transport.(*http.Transport).CloseIdleConnections()
|
// ses.client.Transport.(*http.Transport).CloseIdleConnections()
|
||||||
}
|
// }
|
||||||
|
|
||||||
// EnsureTransporterFinalized will ensure that when the HTTP client is GCed
|
// EnsureTransporterFinalized will ensure that when the HTTP client is GCed
|
||||||
// the runtime will close the idle connections (so that they won't leak)
|
// the runtime will close the idle connections (so that they won't leak)
|
||||||
// this function was adopted from Hashicorp's go-cleanhttp package
|
// this function was adopted from Hashicorp's go-cleanhttp package
|
||||||
// 暂时不用, 标记到以后是否起作用
|
|
||||||
func EnsureTransporterFinalized(httpTransport *http.Transport) {
|
func EnsureTransporterFinalized(httpTransport *http.Transport) {
|
||||||
runtime.SetFinalizer(&httpTransport, func(transportInt **http.Transport) {
|
runtime.SetFinalizer(&httpTransport, func(transportInt **http.Transport) {
|
||||||
(*transportInt).CloseIdleConnections()
|
(*transportInt).CloseIdleConnections()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user