duan205571 2018-04-14 03:19
浏览 218
已采纳

在请求进行过程中修改golang Http Transport是否安全?

I have an application which rotates through proxies on a per request basis.

Currently I have some code which is:

func (mon *Monitor) MassUrlRetrieve(n int, url string) (respBytes []byte) {
    funnel := make(chan []byte)
    go ProductRetrieveTimeout(TIMEOUT_RETRIEVE_URL, funnel)
    for i := 0; i < n; i++ {
        go mon.WrapGetUrlToChannel(funnel, url)
    }
    return <- funnel
}

which basically sends off multiple requests and returns the first one to respond/ timeout if none respond in a timely manner.

In WrapGetUrlToChannel I create a new proxy url are assign it to mon's client.tr.Proxy.

My question is - is it safe to modify the transport of the client while requests are in flight? Or to be safe should I have a different transport and client for each proxy to make sure they do not interfere?

  • 写回答

1条回答 默认 最新

  • doujiu9307 2018-04-24 07:01
    关注

    With the race detector it definitely showed that I shouldn't have been modifying the transport. In the end I decided on rotating *http.Transport around instead of proxies, and using unique clients when making concurrent requests.

    Thanks to @Flimzy

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效