0

I got This error Every time due to difference between the request time and the current time is too large. I found that we need to apply sync_clock option but not able to configuration place.see my configuration please help us to configure to sync clock

Error :

  Expected(200) <=> Actual(403 Forbidden)
  request => {:headers=>{"Content-Length"=>54911, "Content-Type"=>"image/jpeg", "x-amz-acl"=>"public-read", "Cache-Control"=>"max-age=315576000", "Date"=>"Thu, 24 Oct 2013 01:14:14 +0000", "Authorization"=>"changed", "Host"=>"changed"}, :host=>"changed", :mock=>nil, :path=>"/uploads%2Fproject%2Fimage_1%2F697%2FHamburg-Speicher-im-Bau-090825.jpg", :port=>"443", :query=>nil, :scheme=>"https", :body=>#<File:/app/tmp/carrierwave/20131024-0114-2-7499/Hamburg-Speicher-im-Bau-090825.jpg>, :expects=>200, :idempotent=>true, :method=>"PUT"}
  response => #<Excon::Response:0x0000000b72f0a0 @body="<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<Error><Code>RequestTimeTooSkewed</Code><Message>The difference between the request time and the current time is too large.</Message><MaxAllowedSkewMilliseconds>900000</MaxAllowedSkewMilliseconds><RequestId>EA8E8FF76B54D7F3</RequestId><HostId>/RiS+pn3JcKzOoArMhFRYmSBRYwRAptugp8W32XAT4vupukmxMCtHRKIHy7wy9BL</HostId><RequestTime>Thu, 24 Oct 2013 01:14:14 +0000</RequestTime><ServerTime>2013-10-24T01:29:49Z</ServerTime></Error>", @headers={"x-amz-request-id"=>"EA8E8FF76B54D7F3", "x-amz-id-2"=>"/RiS+pn3JcKzOoArMhFRYmSBRYwRAptugp8W32XAT4vupukmxMCtHRKIHy7wy9BL", "Content-Type"=>"application/xml", "Transfer-Encoding"=>"chunked", "Date"=>"Thu, 24 Oct 2013 01:29:47 GMT", "Connection"=>"close", "Server"=>"AmazonS3"}, @status=403>
  vendor/bundle/ruby/1.9.1/gems/excon-0.6.6/lib/excon/connection.rb:190:in `request' 

initializer

  CarrierWave.configure do |config|
  if Rails.env.production?
    config.fog_directory  = 'ese-prod'
    config.fog_host       = 'https://s3.amazonaws.com/ese-prod'
  else
    config.fog_directory  = 'ese-dev'
    config.fog_host       = 'https://s3.amazonaws.com/ese-dev'
  end
  if Rails.env.production? || Rails.env.development?

    config.fog_credentials = {
       :provider               => 'AWS',
       :aws_access_key_id      => 'AAAAAAAAAAA',
       :aws_secret_access_key  => 'BBBBBBBBBBBB',
       :region                 => 'us-east-1'
     }
    config.fog_public     = true
    config.fog_attributes = {'Cache-Control' => 'max-age=315576000'}

    config.root = Rails.root.join('tmp') # adding these...
    config.cache_dir = 'carrierwave' # ...two lines

  # elsif Rails.env.development?
  #  config.storage = :file
  else
    config.storage = :file
  end
end

uploder

class ImageUploader < CarrierWave::Uploader::Base

  include CarrierWave::MiniMagick
  if Rails.env.production? || Rails.env.development?
    storage :fog
  else
    storage :file
  end

  def store_dir
    "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
  end

  version :thumb do
    process :resize_to_limit => [50, 50]
  end

  version :partner do
    process :resize_to_limit => [150, 150]
  end

  def extension_white_list
    %w(jpg jpeg gif png)
  end
end

2 Answers 2

7
+100

This is, unfortunately, a thing that happens. Thankfully there is a fix.

In the initializer you should be able to do something like this:

Fog::Storage.new(fog_credentials).sync_clock

You should be able to use the same values that you are passing to config in your initializer for fog_credentials here. sync_clock makes a simple request to S3 and stores the offset (and then modifies timestamps it sends by the offset). So that should ensure you won't see this error any more (though it shouldn't come up that often, ie if you redeploy to heroku, the new dynos probably would not have the skew still). Hope that clears it up, but happy to help more if needed.

3
  • thanks for your replay its help us in feature for sure because we migrate our app to carrierwave-aws
    – jayesh
    Oct 29, 2013 at 5:46
  • Thank you, I spent more than 2 days for fixing requests!
    – AlxGol
    Oct 7, 2016 at 8:31
  • life saver answer
    – Jin.X
    Mar 25, 2019 at 16:52
2

S3's response means the "Date" header in your request was incorrect by more than 15 minutes. You should check:

  1. Your system time is set correctly
  2. Your timezone is set correctly

See also:

3
  • how to check that its a time zone issue and and what time zone need to set and how to set time zone at heroku ?
    – jayesh
    Oct 28, 2013 at 1:37
  • Time zone is an application setting, in config/application.rb. See here. If your dyno time is skewed, you have no choice but to re-deploy and hope it doesn't happen again, or follow geemus' advice re sync_clock. For others trying to catch up, see groups.google.com/forum/#!topic/ruby-fog/kaehIbyr3kk
    – Taavo
    Oct 28, 2013 at 15:27
  • Yeah, as @Taavo notes, I would expect it to be unusual to get a skewed dyno, so a re-deploy would likely also fix it. sync_clock ensures it, but is probably not often most of the time.
    – geemus
    Oct 29, 2013 at 13:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.