title: Errno::ETIMEDOUT: Connection timed out - connect(2)
body: <p>In production, I'm <strong>occasionally</strong> getting the following error:</p>
  
  <pre><code>Errno::ETIMEDOUT: Connection timed out - connect(2)
  </code></pre>
  
  <p>It only seems to be happening when I generate a PDF using the prawn gem that contains an image that was uploaded by paperclip/aws-sdk to s3.  This probably only happens a couple times a week on an action that is used hundreds of times a day (with no issues), but it results in a 500 error when it does fail.</p>
  
  <p>The trace is: </p>
  
  <pre><code>/opt/ruby-enterprise-1.8.7-2011.03/lib/ruby/1.8/net/http.rb:560:in
  `initialize'
  /opt/ruby-enterprise-1.8.7-2011.03/lib/ruby/1.8/net/http.rb:560:in
  `open'
  /opt/ruby-enterprise-1.8.7-2011.03/lib/ruby/1.8/net/http.rb:560:in
  `connect'
  /opt/ruby-enterprise-1.8.7-2011.03/lib/ruby/1.8/timeout.rb:53:in
  `timeout'
  /opt/ruby-enterprise-1.8.7-2011.03/lib/ruby/1.8/timeout.rb:101:in
  `timeout'
  /opt/ruby-enterprise-1.8.7-2011.03/lib/ruby/1.8/net/http.rb:560:in
  `connect'
  /opt/ruby-enterprise-1.8.7-2011.03/lib/ruby/1.8/net/http.rb:553:in
  `do_start'
  /opt/ruby-enterprise-1.8.7-2011.03/lib/ruby/1.8/net/http.rb:542:in
  `start'
  /opt/ruby-enterprise-1.8.7-2011.03/lib/ruby/1.8/open-uri.rb:242:in
  `open_http'
  /opt/ruby-enterprise-1.8.7-2011.03/lib/ruby/1.8/open-uri.rb:616:in
  `buffer_open'
  /opt/ruby-enterprise-1.8.7-2011.03/lib/ruby/1.8/open-uri.rb:164:in
  `open_loop'
  /opt/ruby-enterprise-1.8.7-2011.03/lib/ruby/1.8/open-uri.rb:162:in
  `catch'
  /opt/ruby-enterprise-1.8.7-2011.03/lib/ruby/1.8/open-uri.rb:162:in
  `open_loop'
  /opt/ruby-enterprise-1.8.7-2011.03/lib/ruby/1.8/open-uri.rb:132:in
  `open_uri'
  /opt/ruby-enterprise-1.8.7-2011.03/lib/ruby/1.8/open-uri.rb:518:in
  `open'
  /opt/ruby-enterprise-1.8.7-2011.03/lib/ruby/1.8/open-uri.rb:30:in
  `open'
  ....rb:57:in `render_image_to_pdf'
  </code></pre>
  
  <p>Line 57:</p>
  
  <pre><code>pdf.image open(image.expiring_url(30.minutes, :full)), :width =&gt; 300, :position =&gt; 20
  </code></pre>
  
  <p>Setup:</p>
  
  <pre><code>Rails 3.0.10
  Ruby 1.8.7EE
  Prawn  0.11.1
  AWS-SDK 1.3.3
  Paperclip 2.5.2
  </code></pre>
  
  <p>What can I do to prevent this error?</p>