We are developing Java services with ECS Fargate. We want to use autoscaling so our services are registered in AWS CloudMap for DNS discovery.
I hit a very strange issue today where all the calls were going to the same instance of the service. So I started an EC2 in the same VPC to dig the service :
[ec2-user@.... ~]$ dig +short something.local
10.253.0.199
10.253.1.129
10.253.0.6
[ec2-user@.... ~]$ dig +short something.local
10.253.1.129
10.253.0.6
10.253.0.199
[ec2-user@.... ~]$ dig +short something.local
10.253.0.6
10.253.0.199
10.253.1.129
It shows that the round robin is correctly working on the AWS side...
We disabled the DNS caching and validated the effects with sun.net.InetAddressCachePolicy.get() returning 0.
We read the underlying code in the OpenJDK code, showing that getByName uses the first entry returned by getAllByName
Then I wrote a code that executes java.net.InetAddress.getAllByName("something.local") every second and prints the result :
10.253.1.129
10.253.0.6
10.253.0.199
========
10.253.1.129
10.253.0.199
10.253.0.6
========
10.253.1.129
10.253.0.6
10.253.0.199
========
We can see here that the result returns always the same address in the first place but the 2 other one are well-balanced...
I tried to find the logic in the source code of the InetAddress class in the openjdk-11 repo (https://github.com/AdoptOpenJDK/openjdk-jdk11/blob/master/src/java.base/share/classes/java/net/InetAddress.java) but I didn't see anything going wrong...
Do you have any solution about that ?