s3 icon indicating copy to clipboard operation
s3 copied to clipboard

S3::Error::RequestTimeout: Your socket connection to the server was not read from or written to within the timeout period. Idle connections will be closed.

Open naquad opened this issue 12 years ago • 7 comments

Hi.

I'm trying to upload an image to my bucket. Thats my code:


require 's3'

service = S3::Service.new(access_key_id: 'xxxxx', secret_access_key: 'xxxxx')
service.buckets # returns me correct list of my buckets so connection is established and works ok
obj = service.buckets.first.objects.build('1.jpg') # now create an object
obj.content = open('1.jpg', 'rb', encoding: 'BINARY') # file i want to upload
obj.save # save it

result is:


/usr/lib/ruby/gems/1.9.1/gems/s3-0.3.11/lib/s3/connection.rb:217:in `handle_response': Your socket connection to the server was not read from or written to within the timeout period. Idle connections will be closed. (S3::Error::RequestTimeout)
    from /usr/lib/ruby/gems/1.9.1/gems/s3-0.3.11/lib/s3/connection.rb:204:in `send_request'
    from /usr/lib/ruby/gems/1.9.1/gems/s3-0.3.11/lib/s3/connection.rb:201:in `send_request'
    from /usr/lib/ruby/gems/1.9.1/gems/s3-0.3.11/lib/s3/connection.rb:89:in `request'
    from /usr/lib/ruby/gems/1.9.1/gems/s3-0.3.11/lib/s3/service.rb:74:in `service_request'
    from /usr/lib/ruby/gems/1.9.1/gems/s3-0.3.11/lib/s3/bucket.rb:171:in `bucket_request'
    from /usr/lib/ruby/gems/1.9.1/gems/s3-0.3.11/lib/s3/object.rb:207:in `object_request'
    from /usr/lib/ruby/gems/1.9.1/gems/s3-0.3.11/lib/s3/object.rb:189:in `put_object'
    from /usr/lib/ruby/gems/1.9.1/gems/s3-0.3.11/lib/s3/object.rb:83:in `save'
    from test.rb:8:in `
'

I'm following your guide and and everything except upload works :( My ruby version is 1.9.3 btw.

naquad avatar Apr 18 '12 16:04 naquad

I'm sorry for the delay. I'm quite busy recently, so I'm afraid you need to debug the code on your own. You can also consider switching to a different S3 library.

qoobaa avatar May 09 '12 09:05 qoobaa

Hi, I had the same problem I will try to debug it but for me solution was:

File.open("file.png", :encoding => "BINARY")

Binary is the key. If I will find out solution You could find it in my fork.

edit

Is really weird because right now it works even without binary attribute. Something strange going on.

mitfik avatar Jul 06 '12 10:07 mitfik

Thanks for reporting, please create a pull request when you fix the problem.

qoobaa avatar Jul 06 '12 14:07 qoobaa

For anyone trying to figure this out, use File.read instead of File.open or open

abunsenonesale avatar Jul 12 '13 06:07 abunsenonesale

@abunsenonesale Do you know how to reproduce this error? Could you also provide explanation for that why read is better then open in this case?

I could not reproduce that error so I do not know if it was related with some specific ruby version or some other black magic. If you could provide some details it will be cool to understand what happened and to fix that.

mitfik avatar Jul 25 '13 09:07 mitfik

I have this now, although it was working when I initially implemented it, it now doesn't!

require "s3"

service = S3::Service.new(
  :access_key_id     => ENV['ACCESS_KEY_ID'],
  :secret_access_key => ENV['SECRET_ACCESS_KEY']
)

bucket_name = ENV['BUCKET_NAME']
file = ENV['FILENAME']

bucket = service.buckets.find(bucket_name)

object = bucket.objects.build(file)
object.content = open(file)
object.save

Result

S3::Error::RequestTimeout: Your socket connection to the server was not read from or written to within the timeout period. Idle connections will be closed.
from /Users/ian/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/s3-0.3.23/lib/s3/connection.rb:216:in `handle_response'

Using : ruby 2.2.3p173 (2015-08-18 revision 51636) [x86_64-darwin14]

[13] pry(main)> object.content = File.open("/Users/ian/Desktop/test.png")
=> #<File:/Users/ian/Desktop/test.png>

IanVaughan avatar Oct 25 '15 20:10 IanVaughan

Reading over here https://github.com/aws/aws-sdk-js/issues/281 it seems it's an issue with the content-length.

mauriciofloresl avatar Jul 30 '18 18:07 mauriciofloresl