hiredis icon indicating copy to clipboard operation
hiredis copied to clipboard

dns resolving issue when using AWS elasticache

Open poznir opened this issue 1 year ago • 5 comments

Hi, we are using AWS, elesticache service for our redis services, using hiredis driver (with hiredis cluster, but it's not relevant) connection is done using dns, provided by AWS the _redisContextConnectTcp method, is suppose to resolve the hosts, and try connecting them one by one until success. the problem is that AWS provides the first host in the resolved DNS host as constant (the "main" one), and the rest are shuffled each time you will resolve it, first ip will stay the same, in our use case we have thousands of connections, and all of them open the initial connection to one node, instead of them being disturbed among all hosts.

the issue only happens when using getaddrinfo in C code, won't happen manually when using host command for example

for example: abc.elesticache.aws.com (example) resolved to

1st try: 123.123.123.123 1.1.1.1 2.2.2.2 3.3.3.3

2nd try: 123.123.123.123 3.3.3.3 1.1.1.1 2.2.2.2

3rd try: 123.123.123.123 2.2.2.2 3.3.3.3 1.1.1.1

...

can you provide a way to shuffle the resolved list, or other alternative to solve this issue?

thank you!

poznir avatar Jun 05 '23 15:06 poznir