Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails: sporadic Carrierwave/Excon errors

Using carrierwave for our uploaders, we get a couple of Excon errors each week from our production app. For example:

Excon::Errors::BadRequest: Expected(200) <=> Actual(400 Bad Request) excon.error.response :body => "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<Error><Code>IncompleteBody</Code><Message>The request body terminated unexpectedly</Message>

We've started wrapping the uploading process in a retry block and it always seems to work fine after another try, but I'm wondering if there is a better solution, as this becomes unwieldy after a while. It seems to me like these errors ought to be handled at a lower level. Is there a better way to handle these issues?

Here's our production configuration:

config.storage = :fog
config.root = Dir.tmpdir
config.cache_dir = 'carrierwave'
config.fog_credentials = {
  provider: 'AWS',
  aws_access_key_id: ENV['AWS_ACCESS_KEY_ID'],
  aws_secret_access_key: ENV['AWS_ACCESS_KEY'],
}

config.fog_directory = ENV['AWS_S3_BUCKET']
config.fog_public = false
config.fog_authenticated_url_expiration = 7.days.to_i

config.enable_processing = true

And we're using gem versions:

fog (1.27.0)
carrierwave (0.10.0)
excon (0.43.0)
like image 955
lobati Avatar asked Jan 21 '15 22:01

lobati


1 Answers

It started working again after I wrote my initializer like this, after overcoming a couple of problems, I think AWS endpoints have changed:

CarrierWave.configure do |config|
  config.fog_credentials = {
      :provider               => 'AWS',
      :aws_access_key_id      => ENV['S3_KEY'],
      :aws_secret_access_key  => ENV['S3_SECRET'],
      :endpoint               => "https://s3.amazonaws.com",
      :region                 => ENV['S3_REGION'] 
  }
  config.fog_directory  = ENV['S3_BUCKET']
end

Also, I thought my region was "us-west-2", looking at my AWS administration console, but it only started working when I changed to "eu-west-1".

Later I realized it is not a good idea to specify that endpoint, in fact it is better to leave it in this situation. Anyways, changing to carrierwave-aws as pointed by lobati solved the problem.

like image 188
RuiMochila Avatar answered Oct 14 '22 17:10

RuiMochila