typeClientstruct{//Transportspecifiesthemechanismbywhichindividual//HTTPrequestsaremade.//Ifnil,DefaultTransportisused.TransportRoundTripper//CheckRedirectspecifiesthepolicyforhandlingredirects.//IfCheckRedirectisnotnil,theclientcallsitbefore//followinganHTTPredirect.Theargumentsreqandviaare//theupcomingrequestandtherequestsmadealready,oldest//first.IfCheckRedirectreturnsanerror,theClient'sGet//methodreturnsboththepreviousResponseand//CheckRedirect'serror(wrappedinaurl.Error)insteadof//issuingtheRequestreq.////IfCheckRedirectisnil,theClientusesitsdefaultpolicy,//whichistostopafter10consecutiverequests.CheckRedirectfunc(req*Request,via[]*Request)error//Jarspecifiesthecookiejar.//IfJarisnil,cookiesarenotsentinrequestsandignored//inresponses.JarCookieJar//Timeoutspecifiesatimelimitforrequestsmadebythis//Client.Thetimeoutincludesconnectiontime,any//redirects,andreadingtheresponsebody.Thetimerremains//runningafterGet,Head,Post,orDoreturnandwill//interruptreadingoftheResponse.Body.////ATimeoutofzeromeansnotimeout.////TheClient'sTransportmustsupporttheCancelRequest//methodorClientwillreturnerrorswhenattemptingtomake//arequestwithGet,Head,Post,orDo.Client'sdefault//Transport(DefaultTransport)supportsCancelRequest.Timeouttime.Duration}以上是部分源码。之前有同学问,client的timeout存在问题,请问有其他人遇见了同样的问题么?
2 回答
富国沪深
TA贡献1790条经验 获得超9个赞
题主的问题很有些莫名其妙,只说有问题但没说明究竟什么问题……不过我还是尝试答一下吧。如果要说Timeout有什么问题,需要注意注释文档里的这句话。ATimeoutofzeromeansnotimeout.如果你要发送很多请求,这个默认特性会害死人,在网络有问题的时候它会造成Client生成的Request和Response对象以及相关goroutine得不到释放,逐渐就吃满内存导致程序挂掉。所以使用go的时候最好不要直接使用http.Get之类的函数,这些都是使用默认Client的,没有Timeout,如果非要用,那就把http.DefaultClient的Timeout设置上吧。最后,我还是预感题主要问的问题跟我说的其实不搭界,啊,题主快现身把你的题目写清楚吧~
添加回答
举报
0/150
提交
取消