Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,10 @@ public static Map<String, String> getPropertiesFromFile(String filename) {
return result;
}

// `InetAddress.getLocalHost().getHostAddress()` could return 127.0.0.1. To avoid
// this situation, we can get current ip through network interface (filtered ipv6,
// loop back, etc.). If the network interface in the machine is more than one, we
// will choose the first IP.
// `InetAddress.getLocalHost().getHostAddress()` could return
// 127.0.0.1 (127.0.1.1 on Debian). To avoid this situation, we can get current
// ip through network interface (filtered ipv6, loop back, etc.).
// If the network interface in the machine is more than one, we will choose the first IP.
public static String getHostIp() throws Exception {
// For K8S, there are too many IPs, it's hard to decide which we should use.
// So we use the environment variable to tell RSS to use which one.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
package org.apache.uniffle.common.util;

import java.lang.reflect.Field;
import java.net.Inet4Address;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.nio.ByteBuffer;
import java.util.Collections;
import java.util.List;
Expand All @@ -35,7 +37,7 @@
import org.apache.uniffle.common.ShuffleIndexResult;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotSame;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
Expand All @@ -57,12 +59,12 @@ public void testGetPropertiesFromFile() {
@Test
public void testGetHostIp() {
try {
String address = InetAddress.getLocalHost().getHostAddress();
String realIp = RssUtils.getHostIp();
assertNotEquals("127.0.0.1", realIp);
if (!address.equals("127.0.0.1")) {
assertEquals(address, realIp);
}
InetAddress ia = InetAddress.getByName(realIp);
assertTrue(ia instanceof Inet4Address);
assertFalse(ia.isLinkLocalAddress() || ia.isAnyLocalAddress() || ia.isLoopbackAddress());
assertTrue(NetworkInterface.getByInetAddress(ia) != null);
assertTrue(ia.isReachable(5000));
setEnv("RSS_IP", "8.8.8.8");
assertEquals("8.8.8.8", RssUtils.getHostIp());
setEnv("RSS_IP", "xxxx");
Expand Down