Can't upload photos to S3 with Fog in Rails : !! #<Excon::Errors::SocketError: Bad address>
Asked Answered
U

2

13

I was able to upload files in the past but for last day day I have not been able to upload files to my S3

When I try to upload a file from the console like

Document.create(remote_file_url: 'http://www.pdf995.com/samples/pdf.pdf')

I get

Document.create(remote_file_url: 'http://www.pdf995.com/samples/pdf.pdf')
   (0.1ms)  BEGIN
  SQL (0.7ms)  INSERT INTO "documents" ("created_at", "file", "updated_at") VALUES ($1, $2, $3) RETURNING "id"  [["created_at", Thu, 12 Feb 2015 22:33:59 EST -05:00], ["file", "pdf.pdf"], ["updated_at", Thu, 12 Feb 2015 22:33:59 EST -05:00]]
   (0.2ms)  ROLLBACK
Excon::Errors::SocketError: Bad address
    from /Users/xxxx/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/openssl/buffering.rb:375:in `syswrite_nonblock'
    from /Users/xxxx/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/openssl/buffering.rb:375:in `write_nonblock'
    from /Users/xxxx/.rvm/gems/ruby-2.0.0-p247@sites/gems/excon-0.13.4/lib/excon/socket.rb:113:in `write'
    from /Users/xxxx/.rvm/gems/ruby-2.0.0-p247@sites/gems/excon-0.13.4/lib/excon/connection.rb:243:in `request_kernel'
    from /Users/xxxx/.rvm/gems/ruby-2.0.0-p247@sites/gems/excon-0.13.4/lib/excon/connection.rb:97:in `request'
    from /Users/xxxx/.rvm/gems/ruby-2.0.0-p247@sites/gems/fog-1.3.1/lib/fog/core/connection.rb:20:in `request'
    from /Users/xxxx/.rvm/gems/ruby-2.0.0-p247@sites/gems/fog-1.3.1/lib/fog/aws/storage.rb:359:in `request'
    from /Users/xxxx/.rvm/gems/ruby-2.0.0-p247@sites/gems/fog-1.3.1/lib/fog/aws/requests/storage/put_object.rb:35:in `put_object'
    from /Users/xxxx/.rvm/gems/ruby-2.0.0-p247@sites/gems/fog-1.3.1/lib/fog/aws/models/storage/file.rb:133:in `save'
    from /Users/xxxx/.rvm/gems/ruby-2.0.0-p247@sites/gems/fog-1.3.1/lib/fog/core/collection.rb:50:in `create'
    from /Users/xxxx/.rvm/gems/ruby-2.0.0-p247@sites/gems/carrierwave-0.10.0/lib/carrierwave/storage/fog.rb:261:in `store'
    from /Users/xxxx/.rvm/gems/ruby-2.0.0-p247@sites/gems/carrierwave-0.10.0/lib/carrierwave/storage/fog.rb:80:in `store!'
    from /Users/xxxx/.rvm/gems/ruby-2.0.0-p247@sites/gems/carrierwave-0.10.0/lib/carrierwave/uploader/store.rb:59:in `block in store!'
    from /Users/xxxx/.rvm/gems/ruby-2.0.0-p247sites/gems/carrierwave-0.10.0/lib/carrierwave/uploader/callbacks.rb:17:in `with_callbacks'
    from /Users/xxxx/.rvm/gems/ruby-2.0.0-p247@sites/gems/carrierwave-0.10.0/lib/carrierwave/uploader/store.rb:58:in `store!'
    from /Users/xxxx/.rvm/gems/ruby-2.0.0-p247@sites/gems/carrierwave-0.10.0/lib/carrierwave/mount.rb:375:in `store!'
... 8 levels...
    from /Users/xxxx/.rvm/gems/ruby-2.0.0-p247@sites/gems/activerecord-4.0.2/lib/active_record/transactions.rb:326:in `block in with_transaction_returning_status'
    from /Users/xxxx/.rvm/gems/ruby-2.0.0-p247@sites/gems/activerecord-4.0.2/lib/active_record/connection_adapters/abstract/database_statements.rb:202:in `block in transaction'
    from /Users/xxxx/.rvm/gems/ruby-2.0.0-p247@sites/gems/activerecord-4.0.2/lib/active_record/connection_adapters/abstract/database_statements.rb:210:in `within_new_transaction'
    from /Users/xxxx/.rvm/gems/ruby-2.0.0-p247@sites/gems/activerecord-4.0.2/lib/active_record/connection_adapters/abstract/database_statements.rb:202:in `transaction'
    from /Users/xxxx/.rvm/gems/ruby-2.0.0-p247@sites/gems/activerecord-4.0.2/lib/active_record/transactions.rb:209:in `transaction'
    from /Users/xxxx/.rvm/gems/ruby-2.0.0-p247@sites/gems/activerecord-4.0.2/lib/active_record/transactions.rb:323:in `with_transaction_returning_status'
    from /Users/xxxx/.rvm/gems/ruby-2.0.0-p247@sites/gems/activerecord-4.0.2/lib/active_record/transactions.rb:270:in `block in save'
    from /Users/xxxx/.rvm/gems/ruby-2.0.0-p247@sites/gems/activerecord-4.0.2/lib/active_record/transactions.rb:281:in `rollback_active_record_state!'
    from /Users/xxxx/.rvm/gems/ruby-2.0.0-p247@sites/gems/activerecord-4.0.2/lib/active_record/transactions.rb:269:in `save'
    from /Users/xxxx/.rvm/gems/ruby-2.0.0-p247@sites/gems/activerecord-4.0.2/lib/active_record/persistence.rb:37:in `create'
    from (irb):11
    from /Users/xxxx/.rvm/gems/ruby-2.0.0-p247@site/gems/railties-4.0.2/lib/rails/commands/console.rb:90:in `start'
    from /Users/xxxx/.rvm/gems/ruby-2.0.0-p247@site/gems/railties-4.0.2/lib/rails/commands/console.rb:9:in `start'
    from /Users/xxxx/.rvm/gems/ruby-2.0.0-p247@site/gems/railties-4.0.2/lib/rails/commands.rb:62:in `<top (required)>'
    from /Users/xxxx/Sites/site/bin/rails:4:in `require'
    from /Users/xxxx/Sites/site/bin/rails:4:in `<main>'2.0.0-p247 :012 >

my uploaded file

# encoding: utf-8
class FileUploader < CarrierWave::Uploader::Base
  def store_dir
    "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
  end

  def extension_white_list
     %w(pdf)
  end    
end

My Model

class Document < ActiveRecord::Base
  mount_uploader :file, FileUploader
end
Urias answered 13/2, 2015 at 3:38 Comment(0)
P
14

Downgrading of OpenSSL version on OS X worked for me.

brew switch openssl 1.0.1l

This is a known issue with the excon gem. Here is the related issue:

https://github.com/excon/excon/issues/467

Prophets answered 18/2, 2015 at 14:20 Comment(2)
Thanks I did not have l but I had e. Again Thanks for the helpUrias
Thanks for this. I had a similar problem on a Python project and solved it by downgrading openssl from version 1.0.2 to 1.0.1k with MacPorts.Hyacinthe
L
5

As @eypatis mentioned, it's an issue with the excon gem. Downgrade to version 1.0.1 as a workaround.

If you don't already have OpenSSL 1.0.1 downloaded via homebrew, you can use the homebrew-versions version:

brew install homebrew/versions/openssl101

Then you can either force-link it to /usr/local:

brew link --force openssl101

Or, to avoid conflicts with other applications that might depend on OpenSSL 1.0.2, pass the path to OpenSSL 1.0.1l when installing Ruby via rbenv + ruby-build:

RUBY_CONFIGURE_OPTS="--with-openssl-dir=/usr/local/Cellar/openssl101/1.0.1l" rbenv install 2.2.1

Once installed, you can verify the OpenSSL version in irb:

irb(main):001:0> require 'openssl'
=> true
irb(main):002:0> OpenSSL::OPENSSL_VERSION
=> "OpenSSL 1.0.1l 15 Jan 2015"
Lithograph answered 19/3, 2015 at 16:19 Comment(1)
Thanks this is a great addition @eypatis Answer https://mcmap.net/q/865677/-can-39-t-upload-photos-to-s3-with-fog-in-rails-lt-excon-errors-socketerror-bad-address-gtUrias

© 2022 - 2024 — McMap. All rights reserved.