Broken pipe errors using aws-s3 with attachment_fu

Rick Olsen’s attachment_fu plugin doesn’t play well with s3 out of the box. Its default settings tell the aws-s3 gem to persist the connection between requests, which seems to cause lots of people problems. Indeed, we were having the same issues on Lovetastic, where we recently switched to an entirely s3-hosted profile photograph setup.

The problem can manifest itself as Errno::EPIPE, Errno::EOFError, or similar exceptions.

I emailed the venerable Marcel Molina Jr, author of the aws-s3 library and his following suggestion did the trick. We’ve been running for several days without a single exception, whereas on launch of the feature we were getting one every hour or so.

You want to patch or otherwise override the attachment_fu plugin’s s3_backend.rb to establish the connection to s3 with :persistent => false.

Beginning at what is line 143 as of trunk today:

Base.establish_connection!(
  :access_key_id     => s3_config[:access_key_id],
  :secret_access_key => s3_config[:secret_access_key],
  :server            => s3_config[:server],
  :port              => s3_config[:port],
  :use_ssl           => s3_config[:use_ssl],
  :persistent        => false 
)