Skip to content

Commit

Permalink
Don't fail on startup when resolving "any" local address (#8393)
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanBratanov committed Jun 20, 2024
1 parent 4456389 commit a9f9826
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 14 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,5 @@ the [releases page](https://github.com/Consensys/teku/releases).
### Additions and Improvements

### Bug Fixes

- Fixed an issue from version 24.6.0 where Teku failed to start on machines with directly assigned public IP addresses (not running under NAT), displaying the error message: `Teku failed to start: java.io.UncheckedIOException: java.net.UnknownHostException: Unable to determine local IPvx Address`
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import static com.google.common.base.Preconditions.checkState;
import static com.google.common.net.InetAddresses.isInetAddress;

import java.io.UncheckedIOException;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
Expand Down Expand Up @@ -153,12 +152,18 @@ private String resolveAnyLocalAddress(final String ipAddress) {
return ipAddress;
}
} catch (final UnknownHostException ex) {
throw new UncheckedIOException(ex);
LOG.error("Failed resolving local address: {}. Trying to use {}", ex.getMessage(), ipAddress);
return ipAddress;
}
}

private String getLocalAddress(final IPVersion ipVersion) throws UnknownHostException {
try {
final InetAddress localHostAddress = InetAddress.getLocalHost();
if (localHostAddress.isAnyLocalAddress()
&& IPVersionResolver.resolve(localHostAddress) == ipVersion) {
return localHostAddress.getHostAddress();
}
final Enumeration<NetworkInterface> networkInterfaces =
NetworkInterface.getNetworkInterfaces();
while (networkInterfaces.hasMoreElements()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import io.libp2p.core.multiformats.Multiaddr;
import java.net.Inet6Address;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.List;
import java.util.Optional;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -62,20 +61,12 @@ void getAdvertisedIps_shouldResolveLocalhostIpWhenInterfaceIpIsAnyLocal() {
@Test
void getAdvertisedIps_shouldResolveLocalhostIpWhenInterfaceIpIsAnyLocalIpv6() {
listenIp = "::0";
final List<String> result;
try {
result = createConfig().getAdvertisedIps();
} catch (Exception ex) {
// local IPv6 not supported
assertThat(ex.getCause()).isInstanceOf(UnknownHostException.class);
assertThat(ex.getMessage()).contains("Unable to determine local IPv6 Address");
return;
}
final List<String> result = createConfig().getAdvertisedIps();
assertThat(result)
.hasSize(1)
.first()
.isNotEqualTo("::0")
.isNotEqualTo("0.0.0.0")
.asString()
.isNotBlank()
.satisfies(
ip -> {
// check the advertised IP is IPv6
Expand Down

0 comments on commit a9f9826

Please sign in to comment.