You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by GitBox <gi...@apache.org> on 2018/06/28 07:48:21 UTC

[GitHub] laijianbin closed pull request #776: [SCB-693] registry microservice failed if failed to get host address

laijianbin closed pull request #776: [SCB-693] registry microservice failed if failed to  get host address
URL: https://github.com/apache/incubator-servicecomb-java-chassis/pull/776
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/foundations/foundation-common/src/main/java/org/apache/servicecomb/foundation/common/net/NetUtils.java b/foundations/foundation-common/src/main/java/org/apache/servicecomb/foundation/common/net/NetUtils.java
index 8cf04d690..587af19df 100644
--- a/foundations/foundation-common/src/main/java/org/apache/servicecomb/foundation/common/net/NetUtils.java
+++ b/foundations/foundation-common/src/main/java/org/apache/servicecomb/foundation/common/net/NetUtils.java
@@ -26,6 +26,7 @@
 import java.net.SocketException;
 import java.net.URI;
 import java.net.URISyntaxException;
+import java.net.UnknownHostException;
 import java.util.Enumeration;
 import java.util.HashMap;
 import java.util.Map;
@@ -55,6 +56,10 @@
   private static String hostAddress;
 
   static {
+    doGetHostNameAndHostAddress();
+  }
+
+  private static void doGetHostNameAndHostAddress() {
     try {
       doGetIpv4AddressFromNetworkInterface();
       // getLocalHost will throw exception in some docker image and sometimes will do a hostname lookup and time consuming
@@ -189,10 +194,16 @@ public static String getRealListenAddress(String schema, String address) {
   }
 
   public static String getHostName() {
+    if (hostName == null) {
+      doGetHostNameAndHostAddress();
+    }
     return hostName;
   }
 
   public static String getHostAddress() {
+    if(hostAddress == null){ 
+      doGetHostNameAndHostAddress();
+    } 
     return hostAddress;
   }
 


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services