Timeout::Error after paperclip update #721

Closed
suzi2000 opened this Issue Jan 29, 2012 · 16 comments

Comments

Projects
None yet

I was using paperclip 2.4.1 with aws-s3 gem. When doing bundle update, i got a Timeout::Error when trying to upload attachments on my local machine (Ubuntu, Rails 3.1.1)

The gem 'aws-sdk' was installed and added to gemfile. I also removed aws-s3 from gemfile but that didnt resolve the problem. I further tried to gem uninstall aws-s3. That still did not solve the timeout error issue. I tried with the latest paperclip gem and also with the git version. For now i reverted back to 2.4.5 which is working with aws-s3.

Member

jyurek commented Jan 30, 2012

So 2.4.5 works, but 2.5.0 doesn't? That's odd. I don't suppose you had any other problems accessing S3 while you were seeing the problem with Paperclip?

Could you send me a stack trace from the Timeout error, as well as your attachment's configuration?

suzi2000 commented Feb 7, 2012

the image download in the browser worked fine from my bucket, while uploading a file didnt work as soon as i switched to 2.5.0 and aws-sdk. When reverting to 2.4.5. it immidiately worked again. Sorry i dont have the stack trace anymore. Is there any configuration change necessary when switching to 2.5.0? The only change i did was changing the gem file to latest paperclip and added the aws-sdk gem.

I had googled for the issue and some other folks had the same problem and recommended deinstalling aws-s3 for incompability issues with aws-sdk. But it didnt fix it on my machine. I will try migrating to 2.5.0 with my next build and then i will post the full trace.

I'm having the exact same issue. Here's a stack trace:

SQL (1.0ms) #HIDDEN
[paperclip] Saving attachments.
[paperclip] saving #HIDDEN...60999e3bce42d3e75f13906608.wv
[AWS S3 200 7.572592] put_object(:acl=>:public_read,:bucket_name=>"#HIDDEN",:content_type=>"application/vnd.wv.csp+wbxml",:data=>#File:/#HIDDEN...uq9co.wv,:key=>"#HIDDEN...e3bce42d3e75f13906608.wv")
[paperclip] saving #HIDDEN...205f1b096f9f940aaad883f915.mp3
[AWS S3 400 21.939233] put_object(:acl=>:public_read,:bucket_name=>#HIDDEN,:content_type=>"audio/mpeg",:data=>#File:/#HIDDEN...210-16125-6g431r.mp3,:key=>"#HIDDEN...0aaad883f915.mp3") AWS::S3::Errors::RequestTimeout: Your socket connection to the server was not read from or written to within the timeout period. Idle connections will be closed.
(0.3ms) ROLLBACK
Completed 500 Internal Server Error in 31562ms

Here's my attachment config. Im using a polymorphic asset model

class Asset < ActiveRecord::Base
  belongs_to :assetable, :polymorphic => true
end
class NewsImage < Asset

  validates_attachment_content_type :asset, 
                                    :content_type => ['image/png', 'image/jpg', 'image/jpeg', 'image/gif'], 
                                    :message => "must be .png, .jpg or .jpeg or .gif files"

  validates_attachment_size :asset, :less_than => 5.megabytes,
                                    :message => "must be smaller than 5 MB (megabytes)."

  has_attached_file :asset, :styles => { :medium    => ["280", :jpg] },
                            :storage => :s3,
                            :s3_credentials => "#{Rails.root}/config/s3.yml",
                            :s3_permissions => :private,
                            :path => ":attachment/:class/:hash.:extension" #defined in initializers

end

Issue #751 might be related...

I'm having similar issues moving from Paperclip 2.7.0 to 3.0.1. This is the related change in my Gemlock.lock file:

-    paperclip (2.7.0)
-      activerecord (>= 2.3.0)
-      activesupport (>= 2.3.2)
+    paperclip (3.0.1)
+      activemodel (>= 3.0.0)
+      activerecord (>= 3.0.0)
+      activesupport (>= 3.0.0)

This update changed the routes to existing files (!) and caused a TimeOut error. Here's my stack (watch out it's huge,):

AWS::S3::Errors::RequestTimeout (Your socket connection to the server was not read from or written to within the timeout period. Idle connections will be closed.):
  aws-sdk (1.3.5) lib/aws/core/client.rb:261:in `return_or_raise'
  aws-sdk (1.3.5) lib/aws/core/client.rb:321:in `client_request'
  (eval):3:in `put_object'
  aws-sdk (1.3.5) lib/aws/s3/s3_object.rb:315:in `write'
  /Users/jasper/.rvm/gems/ruby-1.9.2-p180/bundler/gems/paperclip-7974bd2cf3a9/lib/paperclip/storage/s3.rb:286:in `block in flush_writes'
  /Users/jasper/.rvm/gems/ruby-1.9.2-p180/bundler/gems/paperclip-7974bd2cf3a9/lib/paperclip/storage/s3.rb:272:in `each'
  /Users/jasper/.rvm/gems/ruby-1.9.2-p180/bundler/gems/paperclip-7974bd2cf3a9/lib/paperclip/storage/s3.rb:272:in `flush_writes'
  /Users/jasper/.rvm/gems/ruby-1.9.2-p180/bundler/gems/paperclip-7974bd2cf3a9/lib/paperclip/attachment.rb:197:in `save'
  /Users/jasper/.rvm/gems/ruby-1.9.2-p180/bundler/gems/paperclip-7974bd2cf3a9/lib/paperclip/instance_methods.rb:17:in `block in save_attached_files'
  /Users/jasper/.rvm/gems/ruby-1.9.2-p180/bundler/gems/paperclip-7974bd2cf3a9/lib/paperclip/instance_methods.rb:10:in `block in each_attachment'
  /Users/jasper/.rvm/gems/ruby-1.9.2-p180/bundler/gems/paperclip-7974bd2cf3a9/lib/paperclip/instance_methods.rb:9:in `each'
  /Users/jasper/.rvm/gems/ruby-1.9.2-p180/bundler/gems/paperclip-7974bd2cf3a9/lib/paperclip/instance_methods.rb:9:in `each_attachment'
  /Users/jasper/.rvm/gems/ruby-1.9.2-p180/bundler/gems/paperclip-7974bd2cf3a9/lib/paperclip/instance_methods.rb:16:in `save_attached_files'
  activesupport (3.2.3) lib/active_support/callbacks.rb:416:in `_run__4147552509535814100__save__3272693569031789270__callbacks'
  activesupport (3.2.3) lib/active_support/callbacks.rb:405:in `__run_callback'
  activesupport (3.2.3) lib/active_support/callbacks.rb:385:in `_run_save_callbacks'
  activesupport (3.2.3) lib/active_support/callbacks.rb:81:in `run_callbacks'
  activerecord (3.2.3) lib/active_record/callbacks.rb:264:in `create_or_update'
  activerecord (3.2.3) lib/active_record/persistence.rb:84:in `save'
  activerecord (3.2.3) lib/active_record/validations.rb:50:in `save'
  activerecord (3.2.3) lib/active_record/attribute_methods/dirty.rb:22:in `save'
  activerecord (3.2.3) lib/active_record/transactions.rb:241:in `block (2 levels) in save'
  activerecord (3.2.3) lib/active_record/transactions.rb:295:in `block in with_transaction_returning_status'
  activerecord (3.2.3) lib/active_record/connection_adapters/abstract/database_statements.rb:192:in `transaction'
  activerecord (3.2.3) lib/active_record/transactions.rb:208:in `transaction'
  activerecord (3.2.3) lib/active_record/transactions.rb:293:in `with_transaction_returning_status'
  activerecord (3.2.3) lib/active_record/transactions.rb:241:in `block in save'
  activerecord (3.2.3) lib/active_record/transactions.rb:252:in `rollback_active_record_state!'
  activerecord (3.2.3) lib/active_record/transactions.rb:240:in `save'
  activeadmin (0.4.3) lib/active_admin/resource_controller/callbacks.rb:28:in `block in save_resource'
  activeadmin (0.4.3) lib/active_admin/callbacks.rb:78:in `run_save_callbacks'
  activeadmin (0.4.3) lib/active_admin/resource_controller/callbacks.rb:27:in `save_resource'
  activeadmin (0.4.3) lib/active_admin/resource_controller/callbacks.rb:22:in `block in create_resource'
  activeadmin (0.4.3) lib/active_admin/callbacks.rb:78:in `run_create_callbacks'
  activeadmin (0.4.3) lib/active_admin/resource_controller/callbacks.rb:21:in `create_resource'
  inherited_resources (1.3.1) lib/inherited_resources/actions.rb:33:in `create'
  activeadmin (0.4.3) lib/active_admin/resource_controller/actions.rb:48:in `create'
  actionpack (3.2.3) lib/action_controller/metal/implicit_render.rb:4:in `send_action'
  actionpack (3.2.3) lib/abstract_controller/base.rb:167:in `process_action'
  actionpack (3.2.3) lib/action_controller/metal/rendering.rb:10:in `process_action'
  actionpack (3.2.3) lib/abstract_controller/callbacks.rb:18:in `block in process_action'
  activesupport (3.2.3) lib/active_support/callbacks.rb:447:in `_run__1422550980456589694__process_action__3298708770141221325__callbacks'
  activesupport (3.2.3) lib/active_support/callbacks.rb:405:in `__run_callback'
  activesupport (3.2.3) lib/active_support/callbacks.rb:385:in `_run_process_action_callbacks'
  activesupport (3.2.3) lib/active_support/callbacks.rb:81:in `run_callbacks'
  actionpack (3.2.3) lib/abstract_controller/callbacks.rb:17:in `process_action'
  actionpack (3.2.3) lib/action_controller/metal/rescue.rb:29:in `process_action'
  actionpack (3.2.3) lib/action_controller/metal/instrumentation.rb:30:in `block in process_action'
  activesupport (3.2.3) lib/active_support/notifications.rb:123:in `block in instrument'
  activesupport (3.2.3) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
  activesupport (3.2.3) lib/active_support/notifications.rb:123:in `instrument'
  actionpack (3.2.3) lib/action_controller/metal/instrumentation.rb:29:in `process_action'
  actionpack (3.2.3) lib/action_controller/metal/params_wrapper.rb:205:in `process_action'
  activerecord (3.2.3) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
  actionpack (3.2.3) lib/abstract_controller/base.rb:121:in `process'
  actionpack (3.2.3) lib/abstract_controller/rendering.rb:45:in `process'
  actionpack (3.2.3) lib/action_controller/metal.rb:203:in `dispatch'
  actionpack (3.2.3) lib/action_controller/metal/rack_delegation.rb:14:in `dispatch'
  actionpack (3.2.3) lib/action_controller/metal.rb:246:in `block in action'
  actionpack (3.2.3) lib/action_dispatch/routing/route_set.rb:73:in `call'
  actionpack (3.2.3) lib/action_dispatch/routing/route_set.rb:73:in `dispatch'
  actionpack (3.2.3) lib/action_dispatch/routing/route_set.rb:36:in `call'
  journey (1.0.3) lib/journey/router.rb:68:in `block in call'
  journey (1.0.3) lib/journey/router.rb:56:in `each'
  journey (1.0.3) lib/journey/router.rb:56:in `call'
  actionpack (3.2.3) lib/action_dispatch/routing/route_set.rb:600:in `call'
  sass (3.1.15) lib/sass/plugin/rack.rb:54:in `call'
  warden (1.1.1) lib/warden/manager.rb:35:in `block in call'
  warden (1.1.1) lib/warden/manager.rb:34:in `catch'
  warden (1.1.1) lib/warden/manager.rb:34:in `call'
  actionpack (3.2.3) lib/action_dispatch/middleware/best_standards_support.rb:17:in `call'
  rack (1.4.1) lib/rack/etag.rb:23:in `call'
  rack (1.4.1) lib/rack/conditionalget.rb:35:in `call'
  actionpack (3.2.3) lib/action_dispatch/middleware/head.rb:14:in `call'
  actionpack (3.2.3) lib/action_dispatch/middleware/params_parser.rb:21:in `call'
  actionpack (3.2.3) lib/action_dispatch/middleware/flash.rb:242:in `call'
  rack (1.4.1) lib/rack/session/abstract/id.rb:205:in `context'
  rack (1.4.1) lib/rack/session/abstract/id.rb:200:in `call'
  actionpack (3.2.3) lib/action_dispatch/middleware/cookies.rb:338:in `call'
  activerecord (3.2.3) lib/active_record/query_cache.rb:64:in `call'
  activerecord (3.2.3) lib/active_record/connection_adapters/abstract/connection_pool.rb:467:in `call'
  actionpack (3.2.3) lib/action_dispatch/middleware/callbacks.rb:28:in `block in call'
  activesupport (3.2.3) lib/active_support/callbacks.rb:405:in `_run__4504278435304835923__call__3272693569031789270__callbacks'
  activesupport (3.2.3) lib/active_support/callbacks.rb:405:in `__run_callback'
  activesupport (3.2.3) lib/active_support/callbacks.rb:385:in `_run_call_callbacks'
  activesupport (3.2.3) lib/active_support/callbacks.rb:81:in `run_callbacks'
  actionpack (3.2.3) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
  actionpack (3.2.3) lib/action_dispatch/middleware/reloader.rb:65:in `call'
  actionpack (3.2.3) lib/action_dispatch/middleware/remote_ip.rb:31:in `call'
  actionpack (3.2.3) lib/action_dispatch/middleware/debug_exceptions.rb:16:in `call'
  actionpack (3.2.3) lib/action_dispatch/middleware/show_exceptions.rb:56:in `call'
  railties (3.2.3) lib/rails/rack/logger.rb:26:in `call_app'
  railties (3.2.3) lib/rails/rack/logger.rb:16:in `call'
  actionpack (3.2.3) lib/action_dispatch/middleware/request_id.rb:22:in `call'
  rack (1.4.1) lib/rack/methodoverride.rb:21:in `call'
  rack (1.4.1) lib/rack/runtime.rb:17:in `call'
  activesupport (3.2.3) lib/active_support/cache/strategy/local_cache.rb:72:in `call'
  rack (1.4.1) lib/rack/lock.rb:15:in `call'
  actionpack (3.2.3) lib/action_dispatch/middleware/static.rb:62:in `call'
  railties (3.2.3) lib/rails/engine.rb:479:in `call'
  railties (3.2.3) lib/rails/application.rb:220:in `call'
  rack (1.4.1) lib/rack/content_length.rb:14:in `call'
  railties (3.2.3) lib/rails/rack/log_tailer.rb:14:in `call'
  rack (1.4.1) lib/rack/handler/webrick.rb:59:in `service'
  /Users/jasper/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/webrick/httpserver.rb:111:in `service'
  /Users/jasper/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/webrick/httpserver.rb:70:in `run'
  /Users/jasper/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/webrick/server.rb:183:in `block in start_thread'


    Rendered /Users/jasper/.rvm/gems/ruby-1.9.2-p180/gems/actionpack-3.2.3/lib/action_dispatch/middleware/templates/rescues/_trace.erb (7.7ms)
    Rendered /Users/jasper/.rvm/gems/ruby-1.9.2-p180/gems/actionpack-3.2.3/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (2.5ms)
    Rendered /Users/jasper/.rvm/gems/ruby-1.9.2-p180/gems/actionpack-3.2.3/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb within rescues/layout (40.1ms)

I've now specified the gem version in my gemfile which helps me hit my deadline, but this should definitely get solved or explained somewhere.

swrobel commented Apr 1, 2012

I'm really excited about moving to Paperclip 3 since my app is Ruby 1.9.3/Rails 3.2 but upgrading the gem immediately broke file uploads with this timeout error, so I rolled back to 2.7. This statement from the new gem's install log is about the most confusing thing I've ever read:

 Paperclip 3.0 introduces a non-backward compatible change in your attachment
 path. This will help to prevent attachment name clashes when you have
 multiple attachments with the same name. If you didn't alter your
 attachment's path and are using Paperclip's default, you'll have to add
 `:path` and `:url` to your `has_attached_file` definition. For example:

  has_attached_file :avatar,
  :path => ":rails_root/public/system/:attachment/:id/:style/:filename",
  :url => "/system/:attachment/:id/:style/:filename"

I'm using S3 storage and I was already using custom paths for all of my uploads, so based on that confusing statement, I didn't change any config for 3.0. Here are the relevant backtrace lines:

vendor/bundle/ruby/1.9.1/gems/aws-sdk-1.3.9/lib/aws/core/client.rb:277:in `return_or_raise'
vendor/bundle/ruby/1.9.1/gems/aws-sdk-1.3.9/lib/aws/core/client.rb:362:in `client_request'
(eval):3:in `put_object'
vendor/bundle/ruby/1.9.1/gems/aws-sdk-1.3.9/lib/aws/s3/s3_object.rb:315:in `write'
vendor/bundle/ruby/1.9.1/gems/paperclip-3.0.1/lib/paperclip/storage/s3.rb:286:in `block in flush_writes'
vendor/bundle/ruby/1.9.1/gems/paperclip-3.0.1/lib/paperclip/storage/s3.rb:272:in `each'
vendor/bundle/ruby/1.9.1/gems/paperclip-3.0.1/lib/paperclip/storage/s3.rb:272:in `flush_writes'
vendor/bundle/ruby/1.9.1/gems/paperclip-3.0.1/lib/paperclip/attachment.rb:197:in `save'
vendor/bundle/ruby/1.9.1/gems/paperclip-3.0.1/lib/paperclip/instance_methods.rb:17:in `block in save_attached_files'
vendor/bundle/ruby/1.9.1/gems/paperclip-3.0.1/lib/paperclip/instance_methods.rb:10:in `block in each_attachment'
vendor/bundle/ruby/1.9.1/gems/paperclip-3.0.1/lib/paperclip/instance_methods.rb:9:in `each'
vendor/bundle/ruby/1.9.1/gems/paperclip-3.0.1/lib/paperclip/instance_methods.rb:9:in `each_attachment'
vendor/bundle/ruby/1.9.1/gems/paperclip-3.0.1/lib/paperclip/instance_methods.rb:16:in `save_attached_files'

I definitely think 3.0 needs clearer upgrade instructions. Did something significant change with S3 storage? I'm using CloudFront distribution so my S3 config options are pretty complex:

Paperclip::Attachment.default_options.merge!(
  :storage => 's3',
  :s3_credentials => File.join(Rails.root, 'config', 's3.yml'),
  :s3_host_alias => 'dk0bui34a3uk4.cloudfront.net',
  :url => ':s3_alias_url',
  :s3_protocol => 'https',
  :bucket => 'stacksocial'
)

There don't seem to have been any significant changes in the S3 gem(s), but it doesn't handle the change in the paths very well. Obviously, if Paperclips changes the routes to file, your S3 routes are going to be broken. I think the update message might hold the key after all, but I can't dig into that now.

Anyone have a solution to this? Seems as though there's something not right. I'm having the same issue, but once in a great while, it'll actually work. Which obviously is the worst kind of error, but there's got to be something going on.

I rolled back to 2.7 and it works perfectly. Definitely something not right in 3.0

Contributor

sikachu commented Apr 5, 2012

I've merged #811 into master. Can you guys give it a try and see if it fixes your problem?

wulftone commented Apr 6, 2012

loaded it up, tried it once... it appears to work

ehudros commented Apr 9, 2012

I can also confirm this solved my issue of broken s3 uploads

Fixed for me. Thank you!

Same bug and with the fix, it's work ! thanks

that was a painful wasted day.

sikachu closed this Apr 25, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment