Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolv hostname problem #59

Closed
ismaelvacco opened this issue May 18, 2015 · 5 comments

Comments

Projects
None yet
4 participants
@ismaelvacco
Copy link

commented May 18, 2015

Hi everyone,

When set the ip to create a connect with my redis server, it work right. But if i set the hostname of my redis server, i get follow message:

2015/05/18 19:33:13 [error] 12297#0: *2592 attempt to send data on a closed socket: u:000000000243ABA8, c:0000000000000000, ft:8 eof:0, client: 179.189.133.35, server

The code that work right:

_REDIS_HOST = "10.254.222.23"
-- _REDIS_HOST = "my-server.8cxqzw.0001.sae1.cache.amazonaws.com"
_REDIS_PORT = "6379"
_REDIS_TIMEOUT = 2000 -- set 2 sec
_REDIS_DATABASE = 8

local redis = require "resty.redis"
local red = redis:new()
local ok, err = red:connect(_REDIS_HOST, _REDIS_PORT)
red:set_timeout(_REDIS_TIMEOUT)
red:select(_REDIS_DATABASE)

The code that break down:

-- _REDIS_HOST = "10.254.222.23"
_REDIS_HOST = "my-server.8cxqzw.0001.sae1.cache.amazonaws.com"
_REDIS_PORT = "6379"
_REDIS_TIMEOUT = 2000 -- set 2 sec
_REDIS_DATABASE = 8

local redis = require "resty.redis"
local red = redis:new()
local ok, err = red:connect(_REDIS_HOST, _REDIS_PORT)
red:set_timeout(_REDIS_TIMEOUT)
red:select(_REDIS_DATABASE)
@agentzh

This comment has been minimized.

Copy link
Member

commented May 27, 2015

@ismaelvacco This error happens when your previous redis operation failed with a fatal error (in that case, the underlying cosocket is automatically closed). The fix is simple: just always properly handle the errors of every redis opreations that could possibly fail in your own Lua code.

@jonhatalla

This comment has been minimized.

Copy link

commented Jun 1, 2015

I too have encountered this issue.

The issue seems to be completely related to the hostname not resolving, as interchanging the ip address of the hostname will also resolve the problem.

However in the case of aws - hostnames are preferable because we are using cname records that point to amazon's elasticache instances, which the underlying ip address is not guaranteed to be fixed.

@juniorplenty

This comment has been minimized.

Copy link

commented Jun 2, 2015

+1 @agentzh I think you misunderstood the OP - this is related to hostname resolution vs hard coded IP, meaning the original socket can't even be set up...

@jonhatalla

This comment has been minimized.

Copy link

commented Jun 2, 2015

@ismaelvacco I have a fix for this, and its very clean. My best guess is that Lua does not know how to resolve the hostname.

We are inside a VPC, we have set our vpc to use the 10.8.0.0/16 address range. In my /etc/nginx/nginx.conf, i added the following line in the nginx conf file: resolver 10.8.0.2;

The basis for that line comes from the following url:
http://docs.aws.amazon.com/AmazonVPC/latest/UserGuide/VPC_DHCP_Options.html#AmazonDNS
For example, the DNS Server on a 10.0.0.0/16 network is located at 10.0.0.2

@agentzh

This comment has been minimized.

Copy link
Member

commented Jun 13, 2015

@jonhatalla Yes, you need to configure the "resolver" directive properly. If you handle errors properly you should see the error returned by the earlier connect() call.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.