2012-03-20 3 views
6

が処理されます。実行はRubyのスレッドをクラッシュ例外を有効期限が切れますが、タイムアウト::エラーは、メソッドの呼び出しは次のようになりますときに私は(HTTParty :: POSTリクエストによって引き起こされる)、このスタックが表示される場合があります、なぜ誰もが説明でき

begin 
    response = HTTParty::post(url, options) 
rescue 
    logger.warn("Could not post to #{url}")  
rescue Timeout::Error 
    logger.warn("Could not post to #{url}: timeout")  
end 

スタック:

/usr/local/lib/ruby/1.8/timeout.rb:64:in `timeout' 
/usr/local/lib/ruby/1.8/net/protocol.rb:134:in `rbuf_fill' 
/usr/local/lib/ruby/1.8/net/protocol.rb:104:in `read_all' 
/usr/local/lib/ruby/1.8/net/http.rb:2228:in `read_body_0' 
/usr/local/lib/ruby/1.8/net/http.rb:2181:in `read_body' 
/usr/local/lib/ruby/1.8/net/http.rb:2206:in `body' 
/usr/local/lib/ruby/1.8/net/http.rb:2145:in `reading_body' 
/usr/local/lib/ruby/1.8/net/http.rb:1053:in `request_without_newrelic_trace' 
[GEM_ROOT]/gems/newrelic_rpm-3.1.1/lib/new_relic/agent/instrumentation/net.rb:20:in `request' 
[GEM_ROOT]/gems/newrelic_rpm-3.1.1/lib/new_relic/agent/method_tracer.rb:242:in `trace_execution_scoped' 
[GEM_ROOT]/gems/newrelic_rpm-3.1.1/lib/new_relic/agent/instrumentation/net.rb:19:in `request' 
/usr/local/lib/ruby/1.8/net/http.rb:1037:in `request_without_newrelic_trace' 
/usr/local/lib/ruby/1.8/net/http.rb:543:in `start' 
/usr/local/lib/ruby/1.8/net/http.rb:1035:in `request_without_newrelic_trace' 
[GEM_ROOT]/gems/newrelic_rpm-3.1.1/lib/new_relic/agent/instrumentation/net.rb:20:in `request' 
[GEM_ROOT]/gems/newrelic_rpm-3.1.1/lib/new_relic/agent/method_tracer.rb:242:in `trace_execution_scoped' 
[GEM_ROOT]/gems/newrelic_rpm-3.1.1/lib/new_relic/agent/instrumentation/net.rb:19:in `request' 
[GEM_ROOT]/gems/httparty-0.7.8/lib/httparty/request.rb:69:in `perform' 
[GEM_ROOT]/gems/httparty-0.7.8/lib/httparty.rb:390:in `perform_request' 
[GEM_ROOT]/gems/httparty-0.7.8/lib/httparty.rb:358:in `post' 
[GEM_ROOT]/gems/httparty-0.7.8/lib/httparty.rb:426:in `post' 

あなたが見ることができるように、私はタイムアウト:: Error例外を処理しています。これはRuby 1.8.7です。私は、Ruby 1.8.7で、StandardExceptionとTimeoutExceptionが異なる継承ツリーを持っていることを十分承知していますので、私は両方を扱うが、違いを作るようには見えません。あなたはrescueで例外クラスを省略すると

+0

私は同様の問題があります。さらに悪いのは、私が実際にローカルに偽のサービスを設定していると私は私のローカルシステム上のタイムアウトを起こしたときにエラーが正常に救出されていることです。本番環境では、エラーハンドラは決して呼び出されません。 –

答えて

4

は、それがどんなStandardErrorをキャプチャします。 Timeout::ErrorStandardErrorのサブクラスであるので、それは最初rescue文によってキャプチャされます。別途キャプチャしたい場合は、省略したものの前にそれを配置する必要があります。

begin 
    response = HTTParty::post(url, options) 
rescue Timeout::Error 
    logger.warn("Could not post to #{url}: timeout")  
rescue 
    logger.warn("Could not post to #{url}")  
end 
+5

タイムアウト::エラーがRubyの1.8.7ではStandardErrorのサブクラスではない:http://martinciu.com/2010/12/ruby-timeout-error-is-not-a-standard-error.htmlとのhttp:/ /jerith.livejournal.com/40063.html。さらに、私が直面している問題では、例外はレスキューTimeout :: Errorまたは裸のレスキューのいずれかによって処理されません。 – esilver

関連する問題

 関連する問題