code: private static InetAddress tryLocalHostBeforeReturning(
  				InetAddress preliminaryResult, SocketAddress targetAddress, boolean logging) throws IOException {
  
  		InetAddress localhostName = InetAddress.getLocalHost();
  
  		if (preliminaryResult.equals(localhostName)) {
  			// preliminary result is equal to the local host name
  			return preliminaryResult;
  		}
  		else if (tryToConnect(localhostName, targetAddress, AddressDetectionState.SLOW_CONNECT.getTimeout(), logging)) {
  			// success, we were able to use local host to connect
  			LOG.debug("Preferring {} (InetAddress.getLocalHost()) for local bind point over previous candidate {}",
  					localhostName, preliminaryResult);
  			return localhostName;
  		}
  		else {
  			// we have to make the preliminary result the final result
  			return preliminaryResult;
  		}
  	}
docs: This utility method tries to connect to the JobManager using the InetAddress returned by
  InetAddress.getLocalHost(). The purpose of the utility is to have a final try connecting to
  the target address using the LocalHost before using the address returned.
  We do a second try because the JM might have been unavailable during the first check.
  
  @param preliminaryResult The address detected by the heuristic
  @return either the preliminaryResult or the address returned by InetAddress.getLocalHost() (if
  we are able to connect to targetAddress from there)