首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Typhoeus不会关闭https连接

Typhoeus不会关闭https连接
EN

Stack Overflow用户
提问于 2012-09-24 13:56:39
回答 1查看 2.9K关注 0票数 2

我正在使用Typhoeus来处理我的站点上所有的外部API的HTTP调用,直到最近,它一直工作得很好。我的Rails站点在一段时间后开始没有响应。当我执行netstat时,我注意到在CLOSE_WAIT状态下有大量的连接,它们是由以下代码生成的。

代码语言:javascript
复制
  requests = []
  hydra = Typhoeus::Hydra.new
  urls.each_with_index do |url, index|
    request = Typhoeus::Request.new(url, :timeout => 5000)
    request.on_complete do |response|
      begin
        resp = JSON.parse(response.body)

        if resp["error"]
          p "no deal found for #{factual_ids[index]}"
          { :deals => nil }
        else
          { :deals => resp["merchant"]["deals"] }
        end
      rescue Exception => e
        p e.message
        { :deals => nil }
      end
    end

    requests << request
    hydra.queue(request)
  end

  hydra.run

我发现唯一与我在其他HTTP调用中使用Typhoeus的方式不同的是,上面的urls都是HTTPS urls。我不知道这是否有任何意义,但这是我此时此刻唯一能想到的。以前有没有人见过这个?有没有一个选项可以传递给Typheous,在连接完成后强制关闭它?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-10-07 04:30:37

您使用的是哪种操作系统和Typhoeus版本?一些使用ubuntu的人似乎也遇到了类似的问题。Typhoeus 0.5尚未发布,但它是支持forbid_reuse选项的候选版本。

代码语言:javascript
复制
Typhoeus::Request.new(url, :timeout => 5000, :forbid_reuse => true)

这是问题所在:https://github.com/typhoeus/typhoeus/issues/205,这里是libcurl文档:http://curl.haxx.se/libcurl/c/curl_easy_setopt.html#CURLOPTFORBIDREUSE

您的代码将与Typhoeus 0.5的代码类似:

代码语言:javascript
复制
requests = []
Typhoeus.on_complete do |response|
  begin
    resp = JSON.parse(response.body)

    if resp["error"]
      p "no deal found for #{factual_ids[index]}"
      response.options[:response_body] = { :deals => nil }
    else
      response.options[:response_body] = { :deals => resp["merchant"]["deals"] }
    end
  rescue Exception => e
    p e.message
    response.options[:response_body] = { :deals => nil }
  end
end

hydra = Typhoeus::Hydra.new
urls.each_with_index do |url, index|
  request = Typhoeus::Request.new(url, :timeout => 5000)
  requests << request
  hydra.queue(request)
end

hydra.run
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/12559575

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档