在resque Rails生产模式中调用SOCKSProxy的连接超时

时间:2017-10-15 10:51:12

标签: ruby-on-rails-3 resque socks

我有简单的后台作业,使用resque-pool运行,这使得某些socksproxy调用。当我在Rails开发模式下启动resque-pool时,只要我更改为生产模式,我就可以使用后台作业点击连接超时

中执行时,相同的代码可以正常工作
  • 生产模式下的Rails控制台
  • 从命令行调用的独立ruby脚本

调用类似于:

req = Net::HTTP::Get.new(uri.request_uri)
response = Net::HTTP.SOCKSProxy(@socks_server, @socks_port).start(uri.host, uri.port) do |http|
    http.request(req)
end

调查:

此调用发生在net/http.rb

TCPSocket.open(conn_address, conn_port, @local_host, @local_port)

我发现在生产模式中工作者子进程而不是加载 TCPSocket来自socksify-1.7.0/lib/socksify.rb的{​​{1}}类,它仍然来自提供resolv-replace.rb的红宝石。不知道为什么会这样。

我看到错误:

  

连接超时 - 连接(2)for"" 6455端口:   /usr/lib/ruby/gems/2.1.0/gems/socksify-1.7.0/lib/socksify.rb:178:in   initialize' /usr/lib/ruby/gems/2.1.0/gems/socksify-1.7.0/lib/socksify.rb:178:in 初始化' /usr/lib/ruby/2.1.0/resolv-replace.rb:23:in initialize' /usr/lib/ruby/2.1.0/net/http.rb:879:in打开'   /usr/lib/ruby/2.1.0/net/http.rb:879:in block in connect' /usr/lib/ruby/2.1.0/timeout.rb:76:in超时'   /usr/lib/ruby/2.1.0/net/http.rb:878:in connect' /usr/lib/ruby/2.1.0/net/http.rb:863:in do_start'   /usr/lib/ruby/2.1.0/net/http.rb:852:in start' /usr/lib/ruby/2.1.0/net/http.rb:583:in开始'   /usr/lib/ruby/gems/2.1.0/gems/retries-0.0.5/lib/retries.rb:46:in   call' /usr/lib/ruby/gems/2.1.0/gems/retries-0.0.5/lib/retries.rb:46:in with_retries'   /usr/lib/ruby/gems/2.1.0/gems/resque-1.26.0/lib/resque/job.rb:177:in   block (3 levels) in perform' /usr/lib/ruby/gems/2.1.0/gems/newrelic_rpm-3.16.2.321/lib/new_relic/agent/instrumentation/resque.rb:41:in 阻止在around_perform_with_monitoring'   /usr/lib/ruby/gems/2.1.0/gems/newrelic_rpm-3.16.2.321/lib/new_relic/agent/instrumentation/controller_instrumentation.rb:363:in   `perform_action_with_newrelic_trace'

     
    

/usr/lib/ruby/gems/2.1.0/gems/newrelic_rpm-3.16.2.321/lib/new_relic/agent/instrumentation/resque.rb:33:in     around_perform_with_monitoring' /usr/lib/ruby/gems/2.1.0/gems/resque-1.26.0/lib/resque/job.rb:176:in 阻止(2级)执行'     /usr/lib/ruby/gems/2.1.0/gems/resque-1.26.0/lib/resque/job.rb:172:in     call' /usr/lib/ruby/gems/2.1.0/gems/resque-1.26.0/lib/resque/job.rb:172:in 阻止(3级)执行' ../app/jobs/resque_hooks.rb:15:in     around_perform_job_duration' /usr/lib/ruby/gems/2.1.0/gems/resque-1.26.0/lib/resque/job.rb:172:in 阻止(2级)执行'     /usr/lib/ruby/gems/2.1.0/gems/resque-1.26.0/lib/resque/job.rb:184:in     call' /usr/lib/ruby/gems/2.1.0/gems/resque-1.26.0/lib/resque/job.rb:184:in 执行'     /usr/lib/ruby/gems/2.1.0/gems/resque-1.26.0/lib/resque/worker.rb:290:in     perform' /usr/lib/ruby/gems/2.1.0/gems/resque-1.26.0/lib/resque/worker.rb:229:in 阻止工作'     /usr/lib/ruby/gems/2.1.0/gems/resque-1.26.0/lib/resque/worker.rb:206:in     loop' /usr/lib/ruby/gems/2.1.0/gems/resque-1.26.0/lib/resque/worker.rb:206:in 的工作'     /usr/lib/ruby/gems/2.1.0/gems/resque-pool-0.6.0/lib/resque/pool.rb:396:in     block in spawn_worker!' /usr/lib/ruby/gems/2.1.0/gems/resque-pool-0.6.0/lib/resque/pool.rb:389:in 叉'     /usr/lib/ruby/gems/2.1.0/gems/resque-pool-0.6.0/lib/resque/pool.rb:389:in     spawn_missing_workers_for中的spawn_worker!' /usr/lib/ruby/gems/2.1.0/gems/resque-pool-0.6.0/lib/resque/pool.rb:367:in 阻止'     /usr/lib/ruby/gems/2.1.0/gems/resque-pool-0.6.0/lib/resque/pool.rb:366:in     times' /usr/lib/ruby/gems/2.1.0/gems/resque-pool-0.6.0/lib/resque/pool.rb:366:in spawn_missing_workers_for'     /usr/lib/ruby/gems/2.1.0/gems/resque-pool-0.6.0/lib/resque/pool.rb:352:in     block in maintain_worker_count' /usr/lib/ruby/gems/2.1.0/gems/resque-pool-0.6.0/lib/resque/pool.rb:350:in 各'     /usr/lib/ruby/gems/2.1.0/gems/resque-pool-0.6.0/lib/resque/pool.rb:350:in     maintain_worker_count' /usr/lib/ruby/gems/2.1.0/gems/resque-pool-0.6.0/lib/resque/pool.rb:263:in 开始'     /usr/lib/ruby/gems/2.1.0/gems/resque-pool-0.6.0/lib/resque/pool.rb:89:in     run' /usr/lib/ruby/gems/2.1.0/gems/resque-pool-0.6.0/lib/resque/pool/tasks.rb:17:in 阻止(2级)'     /usr/lib/ruby/gems/2.1.0/gems/rake-11.2.2/lib/rake/task.rb:248:in     call' /usr/lib/ruby/gems/2.1.0/gems/rake-11.2.2/lib/rake/task.rb:248:in 阻止执行'     /usr/lib/ruby/gems/2.1.0/gems/rake-11.2.2/lib/rake/task.rb:243:in     each' /usr/lib/ruby/gems/2.1.0/gems/rake-11.2.2/lib/rake/task.rb:243:in 执行'     /usr/lib/ruby/gems/2.1.0/gems/airbrake-5.5.0/lib/airbrake/rake/task_ext.rb:19:in     {* 1}}阻止invoke_with_call_chain'     /usr/lib/ruby/2.1.0/monitor.rb:211:in execute' /usr/lib/ruby/gems/2.1.0/gems/rake-11.2.2/lib/rake/task.rb:187:in invoke_with_call_chain

  

1 个答案:

答案 0 :(得分:0)

经过更多调查后,由于在生产模式下启用了newrelic gem,因此转向了它。 newrelic需要resolv-replace这与socksify gem和resque后台工作并不顺利。由于我不再需要新的遗物,只需禁用它我就能克服这个问题。