Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why am I getting intermittent Excon::Error::Socket: getaddrinfo: No address associated with hostname (SocketError)?

Rails 4 - Ruby 2.2.2 - Amazon AWS S3 - dragonfly 1.0.12 - dragonfly-s3_data_store 1.2 - fog-aws 0.10.0

Around 99% of the time we have no issues. The issue usually only happens during times when usage is high but I noticed it happen when there were almost no users as well. The line that throws the error:

 # excon/lib/excon/socket.rb
 # line 100 inside the connection method.
 addrinfo = ::Socket.getaddrinfo(*args)

The error happens everywhere in the application. Sometimes the error is seen when there is not a remote connection. - I am no longer able to verify this.

I used Rails loggers to capture the arguments being passed in and there is seemingly no difference between a pass and a fail. Here are some examples:

 # PASS
 ["s3.amazonaws.com", 443, 0, 1, nil, nil, false]
 ["mybucket.s3.amazonaws.com", 443, 0, 1, nil, nil, false]

 # FAIL
 ["mybucket.s3-us-west-1.amazonaws.com", 443, 0, 1, nil, nil, false]

I came across several forums that lead me to believe an update was needed to the excon gem. I upgraded the Excon gem from 0.45.4 to 0.51.0. In addition to that I also updated the Fog gem from 1.36.0 to 1.38.0.

After upgrading the error went from "getaddrinfo: Name or service not known (SocketError)" to "Excon::Error::Socket: getaddrinfo: No address associated with hostname (SocketError)"

The url captured for a failed response is different than one of the urls that passes. I will look in to this further.

UPDATE:

The dragonfly initializer specifies the same path as the one that fails and because url_host overrides the default functionality I decided to remove it.

 # myapp/config/initializers/dragonfly.rb
 ...
 url_host: 'mybucket.s3-us-west-1.amazonaws.com'

This resulted in no change. The same url is still used and is the only one that fails.

like image 938
Peter Black Avatar asked Aug 02 '16 18:08

Peter Black


1 Answers

I had this error, too. In my case, the culprit was either the server load (a slow file upload) or it was special characters in the filename. Since you also see this during low usage times, you might want to look at the filenames that people upload. For me the error typically occurred, when someone uploaded a file with German umlauts (ä,ö,ü,ß) in the name of the file.

So please try to upload a file with some special character in the name and tell us whether this reproduces the error faithfully.

If this is the case, then simply escape the special characters or name the file differently. Here is a description of the special characters issue: https://github.com/markevans/dragonfly-s3_data_store/issues/6.

like image 150
morgler Avatar answered Sep 17 '22 07:09

morgler