You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@rocketmq.apache.org by fu...@apache.org on 2022/11/13 10:02:38 UTC

[rocketmq] branch develop updated: [ISSUE #5512] Skip the unnecessary network interfaces. (#5513)

This is an automated email from the ASF dual-hosted git repository.

fuyou pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/rocketmq.git


The following commit(s) were added to refs/heads/develop by this push:
     new 407d2738f [ISSUE #5512] Skip the unnecessary network interfaces. (#5513)
407d2738f is described below

commit 407d2738f2d8b20a8ea264c75dbfc876ecb8519e
Author: echooymxq <ec...@gmail.com>
AuthorDate: Sun Nov 13 18:02:32 2022 +0800

    [ISSUE #5512] Skip the unnecessary network interfaces. (#5513)
---
 .../src/main/java/org/apache/rocketmq/common/utils/NetworkUtil.java | 6 +++---
 .../src/test/java/org/apache/rocketmq/common/NetworkUtilTest.java   | 4 +++-
 2 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/common/src/main/java/org/apache/rocketmq/common/utils/NetworkUtil.java b/common/src/main/java/org/apache/rocketmq/common/utils/NetworkUtil.java
index fa1d89314..5d05bc12f 100644
--- a/common/src/main/java/org/apache/rocketmq/common/utils/NetworkUtil.java
+++ b/common/src/main/java/org/apache/rocketmq/common/utils/NetworkUtil.java
@@ -95,12 +95,12 @@ public class NetworkUtil {
             ArrayList<String> ipv4Result = new ArrayList<>();
             ArrayList<String> ipv6Result = new ArrayList<>();
             while (enumeration.hasMoreElements()) {
-                final NetworkInterface networkInterface = enumeration.nextElement();
-                if (isBridge(networkInterface)) {
+                final NetworkInterface nif = enumeration.nextElement();
+                if (isBridge(nif) || nif.isVirtual() || nif.isPointToPoint() || !nif.isUp()) {
                     continue;
                 }
 
-                final Enumeration<InetAddress> en = networkInterface.getInetAddresses();
+                final Enumeration<InetAddress> en = nif.getInetAddresses();
                 while (en.hasMoreElements()) {
                     final InetAddress address = en.nextElement();
                     if (!address.isLoopbackAddress()) {
diff --git a/common/src/test/java/org/apache/rocketmq/common/NetworkUtilTest.java b/common/src/test/java/org/apache/rocketmq/common/NetworkUtilTest.java
index 78ec6d0be..aa4d355f8 100644
--- a/common/src/test/java/org/apache/rocketmq/common/NetworkUtilTest.java
+++ b/common/src/test/java/org/apache/rocketmq/common/NetworkUtilTest.java
@@ -16,6 +16,7 @@
  */
 package org.apache.rocketmq.common;
 
+import java.net.InetAddress;
 import org.apache.rocketmq.common.utils.NetworkUtil;
 import org.junit.Test;
 
@@ -23,10 +24,11 @@ import static org.assertj.core.api.Assertions.assertThat;
 
 public class NetworkUtilTest {
     @Test
-    public void testGetLocalAddress() throws Exception {
+    public void testGetLocalAddress() {
         String localAddress = NetworkUtil.getLocalAddress();
         assertThat(localAddress).isNotNull();
         assertThat(localAddress.length()).isGreaterThan(0);
+        assertThat(localAddress).isNotEqualTo(InetAddress.getLoopbackAddress().getHostAddress());
     }
 
     @Test