aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYe Xianjin <advancedxy@gmail.com>2014-09-15 21:53:38 -0700
committerPatrick Wendell <pwendell@gmail.com>2014-09-15 21:53:38 -0700
commitfebafefa5aaee3b3eda5e1b45a75bc6d8e7fb13f (patch)
tree7d0b0b808ba150c5968144b870da5818a303a5d4
parentecf0c02935815f0d4018c0e30ec4c784e60a5db0 (diff)
downloadspark-febafefa5aaee3b3eda5e1b45a75bc6d8e7fb13f.tar.gz
spark-febafefa5aaee3b3eda5e1b45a75bc6d8e7fb13f.tar.bz2
spark-febafefa5aaee3b3eda5e1b45a75bc6d8e7fb13f.zip
[SPARK-3040] pick up a more proper local ip address for Utils.findLocalIpAddress method
Short version: NetworkInterface.getNetworkInterfaces returns ifs in reverse order compared to ifconfig output. It may pick up ip address associated with tun0 or virtual network interface. See [SPARK_3040](https://issues.apache.org/jira/browse/SPARK-3040) for more detail Author: Ye Xianjin <advancedxy@gmail.com> Closes #1946 from advancedxy/SPARK-3040 and squashes the following commits: f33f6b2 [Ye Xianjin] add windows support 087a785 [Ye Xianjin] reverse the Networkinterface.getNetworkInterfaces output order to get a more proper local ip address.
-rw-r--r--core/src/main/scala/org/apache/spark/util/Utils.scala7
1 files changed, 6 insertions, 1 deletions
diff --git a/core/src/main/scala/org/apache/spark/util/Utils.scala b/core/src/main/scala/org/apache/spark/util/Utils.scala
index 79943766d0..c76b7af184 100644
--- a/core/src/main/scala/org/apache/spark/util/Utils.scala
+++ b/core/src/main/scala/org/apache/spark/util/Utils.scala
@@ -530,7 +530,12 @@ private[spark] object Utils extends Logging {
if (address.isLoopbackAddress) {
// Address resolves to something like 127.0.1.1, which happens on Debian; try to find
// a better address using the local network interfaces
- for (ni <- NetworkInterface.getNetworkInterfaces) {
+ // getNetworkInterfaces returns ifs in reverse order compared to ifconfig output order
+ // on unix-like system. On windows, it returns in index order.
+ // It's more proper to pick ip address following system output order.
+ val activeNetworkIFs = NetworkInterface.getNetworkInterfaces.toList
+ val reOrderedNetworkIFs = if (isWindows) activeNetworkIFs else activeNetworkIFs.reverse
+ for (ni <- reOrderedNetworkIFs) {
for (addr <- ni.getInetAddresses if !addr.isLinkLocalAddress &&
!addr.isLoopbackAddress && addr.isInstanceOf[Inet4Address]) {
// We've found an address that looks reasonable!