An exception that has ended with an expired Ruby thread failure, but Timeout :: Error is being processed

Can someone explain why I can see this stack (called by HTTParty :: post request) when the method call looks like this:

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 

Stack:

 /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' 

As you can see, I am handling a Timeout :: Error exception. This is in Ruby 1.8.7. I am well aware that in Ruby 1.8.7, StandardException and TimeoutException have different inheritance trees, so I handle both, but that doesn't seem to matter.

+6
source share
1 answer

When you omit the exception class in rescue , it will catch any StandardError . Since Timeout::Error is a subclass of StandardError , it will be captured by the first rescue statement. If you want to capture it separately, you must put it before the missing one:

 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 
+4
source

Source: https://habr.com/ru/post/911166/


All Articles