Commit 4163e157 authored by Jan-Erik Rediger's avatar Jan-Erik Rediger
Browse files

Always resolve v4 and v6 addresses

Otherwise the code will never work on v6-only hosts, when the domain
resolves to v4 addresses.

The latency is negligible. The order of resolved addresses is already a
good hint on which connectivity is available.
If IPv6 is returned, but no such connectivity is there, it's a system
configuration mistake.

Additionally, repetitive re-connections to Redis should be avoided
anyway.
parent b7205d35
......@@ -319,20 +319,18 @@ static int _redisContextConnectTcp(redisContext *c, const char *addr, int port,
snprintf(_port, 6, "%d", port);
memset(&hints,0,sizeof(hints));
hints.ai_family = AF_INET;
hints.ai_family = AF_UNSPEC;
hints.ai_socktype = SOCK_STREAM;
/* Try with IPv6 if no IPv4 address was found. We do it in this order since
* in a Redis client you can't afford to test if you have IPv6 connectivity
* as this would add latency to every connect. Otherwise a more sensible
* route could be: Use IPv6 if both addresses are available and there is IPv6
* connectivity. */
/* We always check for both IPv4 and IPv6 addresses.
* This is the only way it will work on v6-only hosts
* (and will work on v4-only hosts as well).
* In general we can rely on the order of addresses returned
* to avoid additional connect latency.
*/
if ((rv = getaddrinfo(c->tcp.host,_port,&hints,&servinfo)) != 0) {
hints.ai_family = AF_INET6;
if ((rv = getaddrinfo(addr,_port,&hints,&servinfo)) != 0) {
__redisSetError(c,REDIS_ERR_OTHER,gai_strerror(rv));
return REDIS_ERR;
}
__redisSetError(c,REDIS_ERR_OTHER,gai_strerror(rv));
return REDIS_ERR;
}
for (p = servinfo; p != NULL; p = p->ai_next) {
addrretry:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment