This is an automated email from the ASF dual-hosted git repository.
snazy pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/polaris.git
The following commit(s) were added to refs/heads/main by this push:
new d4bd5d665 ensure AddressResolver supports localhost even if ipv6 is
disabled in sysctl but not /etc/hosts (#3285)
d4bd5d665 is described below
commit d4bd5d66515338550bde883f21a426e4de7ffe0b
Author: Romain Manni-Bucau <[email protected]>
AuthorDate: Wed Dec 17 17:16:38 2025 +0100
ensure AddressResolver supports localhost even if ipv6 is disabled in
sysctl but not /etc/hosts (#3285)
---
.../nosql/quarkus/distcache/AddressResolver.java | 32 ++++++++++++++++++----
1 file changed, 26 insertions(+), 6 deletions(-)
diff --git
a/persistence/nosql/persistence/cdi/quarkus-distcache/src/main/java/org/apache/polaris/persistence/nosql/quarkus/distcache/AddressResolver.java
b/persistence/nosql/persistence/cdi/quarkus-distcache/src/main/java/org/apache/polaris/persistence/nosql/quarkus/distcache/AddressResolver.java
index a0ea189b6..3abdf83a6 100644
---
a/persistence/nosql/persistence/cdi/quarkus-distcache/src/main/java/org/apache/polaris/persistence/nosql/quarkus/distcache/AddressResolver.java
+++
b/persistence/nosql/persistence/cdi/quarkus-distcache/src/main/java/org/apache/polaris/persistence/nosql/quarkus/distcache/AddressResolver.java
@@ -35,6 +35,7 @@ import java.util.List;
import java.util.Set;
import java.util.stream.IntStream;
import java.util.stream.Stream;
+import org.jspecify.annotations.NonNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -54,14 +55,27 @@ record AddressResolver(DnsClient dnsClient, List<String>
searchList) {
static {
try {
+ IP_V4_ONLY =
Boolean.parseBoolean(System.getProperty("java.net.preferIPv4Stack", "false"));
LOCAL_ADDRESSES =
networkInterfaces()
.flatMap(
ni ->
- ni.getInterfaceAddresses().stream()
- // Need to do this InetAddress->byte[]->InetAddress
dance to get rid of
- // host-address suffixes as in `0:0:0:0:0:0:0:1%lo`
- .map(InterfaceAddress::getAddress)
+ Stream.concat(
+ // localhost can be ipv6 when sysctl disable ipv6
+ // if ::1 is registered for localhost in
/etc/hosts
+ // in this case java stack can still capture it
+ // and it will work (even if not great)
+ // this is a workaround to ensure at least
localhost is
+ // in the list but this could be more general to
all /etc/hosts
+ // mappings
+ IP_V4_ONLY ||
!"lo".equalsIgnoreCase(ni.getName())
+ ? Stream.empty()
+ : findLocalhostAddresses(),
+ ni.getInterfaceAddresses().stream()
+ // Need to do this
InetAddress->byte[]->InetAddress dance to get
+ // rid of
+ // host-address suffixes as in
`0:0:0:0:0:0:0:1%lo`
+ .map(InterfaceAddress::getAddress))
.map(InetAddress::getAddress)
.map(
a -> {
@@ -75,13 +89,19 @@ record AddressResolver(DnsClient dnsClient, List<String>
searchList) {
})
.map(InetAddress::getHostAddress))
.collect(toUnmodifiableSet());
-
- IP_V4_ONLY =
Boolean.parseBoolean(System.getProperty("java.net.preferIPv4Stack", "false"));
} catch (SocketException e) {
throw new RuntimeException(e);
}
}
+ private static @NonNull Stream<InetAddress> findLocalhostAddresses() {
+ try {
+ return Stream.of(InetAddress.getAllByName("localhost"));
+ } catch (final RuntimeException | UnknownHostException e) {
+ return Stream.empty();
+ }
+ }
+
/**
* Uses a "default" {@link DnsClient} using the first {@code nameserver} and
the {@code search}
* list configured in {@code /etc/resolv.conf}.