title: Ruby Net::HTTP execution expired
body: <p>Using Net::HTTP, I periodically find that the code below rescues from StandardError with a message of "execution expired", despite the fact that the web server logs from the accessed URL show the corresponding response was sent quickly.  When the web server logs show a response that takes more than 5 seconds, I generally see the code rescue from Timeout::Error.</p>
  
  <p>What case would cause the code below to rescue from StandardError with "execution expired" <strong>instead of</strong> rescuing from Timeout::Error?</p>
  
  <p>This code is running in a multi-threaded program on a relatively ancient Ruby 1.9.3, on a platform that does not support newer versions of Ruby.  Although the program is multi-threaded, the code shown only runs on a single thread.</p>
  
  <pre><code>begin
    connection = Net::HTTP.new(uri.host, uri.port)
    connection.open_timeout = 5
    connection.read_timeout = 5
    connection.start do |http|
      request = Net::HTTP::Post.new("/reader_events")
      request.body = body
      response = http.request(request)
    end
  rescue StandardError =&gt; std_error
    log "error sending event to server: #{std_error}"
  rescue Timeout::Error =&gt; error
    log "timeout sending event to server"
  end
  </code></pre>