[ 
https://issues.apache.org/jira/browse/SCB-693?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16527002#comment-16527002
 ] 

ASF GitHub Bot commented on SCB-693:
------------------------------------

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

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 dbe87032d..b3fdf89e8 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
@@ -55,6 +55,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
@@ -193,10 +197,20 @@ public static String getRealListenAddress(String schema, 
String address) {
   }
 
   public static String getHostName() {
+    //If failed to get host name ,micro-service will registry failed
+    //So I add retry mechanism
+    if (hostName == null) {
+      doGetHostNameAndHostAddress();
+    }
     return hostName;
   }
 
   public static String getHostAddress() {
+    //If failed to get host name ,micro-service will registry failed
+    //So I add retry mechanism
+    if(hostAddress == null){
+      doGetHostNameAndHostAddress();
+    }
     return hostAddress;
   }
 
diff --git 
a/foundations/foundation-common/src/test/java/org/apache/servicecomb/foundation/common/net/TestNetUtils.java
 
b/foundations/foundation-common/src/test/java/org/apache/servicecomb/foundation/common/net/TestNetUtils.java
index 85eebe27a..52a8ec104 100644
--- 
a/foundations/foundation-common/src/test/java/org/apache/servicecomb/foundation/common/net/TestNetUtils.java
+++ 
b/foundations/foundation-common/src/test/java/org/apache/servicecomb/foundation/common/net/TestNetUtils.java
@@ -107,4 +107,18 @@ public void testCanTcpListenYes() throws IOException {
 
     Assert.assertTrue(NetUtils.canTcpListen(address, port));
   }
+
+  @Test public void testGetHostName(){
+    String hostName = NetUtils.getHostName();
+    Assert.assertNotEquals(null,hostName);
+    hostName = null;
+    Assert.assertNotEquals(hostName,NetUtils.getHostName());
+  }
+
+  @Test public void testGetHostAddress(){
+      String hostAddress = NetUtils.getHostAddress();
+      Assert.assertNotEquals(null,hostAddress);
+      hostAddress = null;
+      Assert.assertNotEquals(hostAddress,NetUtils.getHostAddress());
+  }
 }


 

----------------------------------------------------------------
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:
us...@infra.apache.org


> registry microservice failed if get host address failed
> -------------------------------------------------------
>
>                 Key: SCB-693
>                 URL: https://issues.apache.org/jira/browse/SCB-693
>             Project: Apache ServiceComb
>          Issue Type: Task
>            Reporter: laijianbin
>            Assignee: laijianbin
>            Priority: Major
>
> !20180625-101900(eSpace).png!



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to