Skip to content

Commit 087a785

Browse files
committed
reverse the Networkinterface.getNetworkInterfaces output order to
get a more proper local ip address.
1 parent 6b8de0e commit 087a785

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

core/src/main/scala/org/apache/spark/util/Utils.scala

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,10 @@ private[spark] object Utils extends Logging {
493493
if (address.isLoopbackAddress) {
494494
// Address resolves to something like 127.0.1.1, which happens on Debian; try to find
495495
// a better address using the local network interfaces
496-
for (ni <- NetworkInterface.getNetworkInterfaces) {
496+
// getNetworkInterfaces returns ifs in reverse order compared to ifconfig output order
497+
// on unix-like system. On windows, it returns in index order.
498+
// It's more proper to pick ip address following the ifconfig output order
499+
for (ni <- NetworkInterface.getNetworkInterfaces.toList.reverse) {
497500
for (addr <- ni.getInetAddresses if !addr.isLinkLocalAddress &&
498501
!addr.isLoopbackAddress && addr.isInstanceOf[Inet4Address]) {
499502
// We've found an address that looks reasonable!

0 commit comments

Comments
 (0)