Alpine image unable to resolve more than 63 IP addresses for domain (`java.net.InetAddress`)
I'm using:
- Docker image:
alpine:3.18.3
, - Java:
openjdk11-jre
:
openjdk version "11.0.20" 2023-07-18
OpenJDK Runtime Environment (build 11.0.20+8-alpine-r0)
OpenJDK 64-Bit Server VM (build 11.0.20+8-alpine-r0, mixed mode)
Problem description:
When I try to use java.net.InetAddress#getAllByName
to get all IP addresses for host with more than 63 addresses I'm getting exception:
java.net.UnknownHostException: 70ips.test-domain.com: Name has no usable address
at java.base/java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method)
at java.base/java.net.InetAddress$PlatformNameService.lookupAllHostAddr(InetAddress.java:930)
at java.base/java.net.InetAddress.getAddressesFromNameService(InetAddress.java:1543)
at java.base/java.net.InetAddress$NameServiceAddresses.get(InetAddress.java:848)
at java.base/java.net.InetAddress.getAllByName0(InetAddress.java:1533)
at java.base/java.net.InetAddress.getAllByName(InetAddress.java:1386)
at java.base/java.net.InetAddress.getAllByName(InetAddress.java:1307)
at com.issue.Main.main(Main.java:27)
It looks that the native implementation of java.net.InetAddress#getAllByName
in libnet
is failing.
I encountered this problem only for Alpine image. For other Linux distribution (e.g. Ubuntu) it seems that there is no such a problem. The problem does not appear when the host is resolved for less than 64 IP addresses.
Reproduce the problem:
-
Create record of type
A
using Route 53 in AWS see documentation with host70ips.test-domain.com
and 70 IPs as a value; -
Create Java code which resolves IP addresses for that host:
import java.net.InetAddress; import java.net.UnknownHostException; import java.util.Arrays; import java.util.stream.Collectors; public class TestApp { public static void main(String[] args) throws UnknownHostException { final String host = "70ips.test-domain.com"; final InetAddress[] all = InetAddress.getAllByName(host); printResults(all, host); } private static void printResults(InetAddress[] all, String host) { final String addressesAsString = Arrays.stream(all) .map(InetAddress::getHostAddress) .collect(Collectors.joining(", ", "\n", "")); final String msg = String.format( "URL: '%s'. InetAddresses[%s]: %s", host, all.length, addressesAsString ); System.out.println(msg); } }
-
Create Docker image based on Alpine image using Dockerfile like:
FROM alpine:3.18.3 RUN sed -ie "s/https/http/g" /etc/apk/repositories RUN apk add \ --no-cache \ --repository http://dl-cdn.alpinelinux.org/alpine/v3.14/main \ ca-certificates RUN apk add openjdk11-jre COPY target/app-jar-with-dependencies.jar app.jar CMD ["sh", "-c", "exec java -jar app.jar"]
-
Run the docker container using command:
docker run <image_name>
; -
In logs there will be exception:
java.net.UnknownHostException: 70ips.test-domain.com: Name has no usable address at java.base/java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method) at java.base/java.net.InetAddress$PlatformNameService.lookupAllHostAddr(InetAddress.java:930) at java.base/java.net.InetAddress.getAddressesFromNameService(InetAddress.java:1543) at java.base/java.net.InetAddress$NameServiceAddresses.get(InetAddress.java:848) at java.base/java.net.InetAddress.getAllByName0(InetAddress.java:1533) at java.base/java.net.InetAddress.getAllByName(InetAddress.java:1386) at java.base/java.net.InetAddress.getAllByName(InetAddress.java:1307) at com.issue.Main.main(Main.java:27)
Questions:
- Is 63 IP addresses some known limitation?
- Do you know how can I fix the issue?
- Is it bug in Alpine?
Expected and actual outcome:
I tried to use java.net.InetAddress#getAllByName
to get all IP addresses for host with more than 63 addresses. I expected to get the array of IP addresses for given host. Actually I got exception java.net.UnknownHostException
with "Name has no usable address" message.
See also stackoverflow question about the issue.