[GitHub] incubator-rocketmq pull request #157: [Rocketmq-277] fix get localhost throw...
Github user fuyou001 closed the pull request at: https://github.com/apache/incubator-rocketmq/pull/157 --- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---
[GitHub] incubator-rocketmq pull request #157: [Rocketmq-277] fix get localhost throw...
Github user vongosling commented on a diff in the pull request: https://github.com/apache/incubator-rocketmq/pull/157#discussion_r135705543 --- Diff: common/src/main/java/org/apache/rocketmq/common/MixAll.java --- @@ -407,12 +408,50 @@ private static String localhost() { InetAddress addr = InetAddress.getLocalHost(); return addr.getHostAddress(); } catch (Throwable e) { +try { +String candidatesHost = getLocalhostByNetworkInterface(); +if (candidatesHost != null) +return candidatesHost; + +} catch (Exception ignored) { +} + throw new RuntimeException("InetAddress java.net.InetAddress.getLocalHost() throws UnknownHostException" + FAQUrl.suggestTodo(FAQUrl.UNKNOWN_HOST_EXCEPTION), e); } } +private static String getLocalhostByNetworkInterface() throws SocketException { --- End diff -- I have marked it using FIXME label. reverse logic comparing to RemotingUtil method, we could consider to refactor it in RocketMQ 5.0. --- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---
[GitHub] incubator-rocketmq pull request #157: [Rocketmq-277] fix get localhost throw...
Github user lizhanhui commented on a diff in the pull request: https://github.com/apache/incubator-rocketmq/pull/157#discussion_r135698929 --- Diff: common/src/main/java/org/apache/rocketmq/common/MixAll.java --- @@ -407,12 +408,50 @@ private static String localhost() { InetAddress addr = InetAddress.getLocalHost(); return addr.getHostAddress(); } catch (Throwable e) { +try { +String candidatesHost = getLocalhostByNetworkInterface(); +if (candidatesHost != null) +return candidatesHost; + +} catch (Exception ignored) { +} + throw new RuntimeException("InetAddress java.net.InetAddress.getLocalHost() throws UnknownHostException" + FAQUrl.suggestTodo(FAQUrl.UNKNOWN_HOST_EXCEPTION), e); } } +private static String getLocalhostByNetworkInterface() throws SocketException { --- End diff -- RemotingUtil has already had a similar method, aka, getLocalAddress, is there any rational reason to create a duplicated one? --- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---
[GitHub] incubator-rocketmq pull request #157: [Rocketmq-277] fix get localhost throw...
Github user dongeforever commented on a diff in the pull request: https://github.com/apache/incubator-rocketmq/pull/157#discussion_r135681743 --- Diff: common/src/test/java/org/apache/rocketmq/common/MixAllTest.java --- @@ -93,4 +90,12 @@ public void testString2File() throws IOException { MixAll.string2File("MixAll_testString2File", fileName); assertThat(MixAll.file2String(fileName)).isEqualTo("MixAll_testString2File"); } + +@Test +public void test_getLocalhostByNetworkInterface() throws Exception { +Method method = MixAll.class.getDeclaredMethod("getLocalhostByNetworkInterface"); +method.setAccessible(true); +Object invoke = method.invoke(null); +assertThat(invoke).isNotNull(); +} --- End diff -- It may be better to avoid reflection. Consider making this method be public or package-accessible --- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---
[GitHub] incubator-rocketmq pull request #157: [Rocketmq-277] fix get localhost throw...
Github user zhouxinyu commented on a diff in the pull request: https://github.com/apache/incubator-rocketmq/pull/157#discussion_r135678680 --- Diff: common/src/main/java/org/apache/rocketmq/common/MixAll.java --- @@ -407,12 +408,50 @@ private static String localhost() { InetAddress addr = InetAddress.getLocalHost(); return addr.getHostAddress(); } catch (Throwable e) { +try { +String candidatesHost = getLocalhostByNetworkInterface(); +if (candidatesHost != null) +return candidatesHost; + +} catch (Exception ignored) { +} + throw new RuntimeException("InetAddress java.net.InetAddress.getLocalHost() throws UnknownHostException" + FAQUrl.suggestTodo(FAQUrl.UNKNOWN_HOST_EXCEPTION), e); } } +private static String getLocalhostByNetworkInterface() throws SocketException { +List candidatesHost = new ArrayList(); +Enumeration enumeration = NetworkInterface.getNetworkInterfaces(); + +while (enumeration.hasMoreElements()) { +NetworkInterface networkInterface = enumeration.nextElement(); +if ("docker0".equals(networkInterface.getName()) || !networkInterface.isUp()) { --- End diff -- Do we have a test in docker container for this method ? --- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---
[GitHub] incubator-rocketmq pull request #157: Rocketmq 277
GitHub user fuyou001 opened a pull request: https://github.com/apache/incubator-rocketmq/pull/157 Rocketmq 277 Motivation: fix bug [ROCKETMQ-277](https://issues.apache.org/jira/browse/ROCKETMQ-277) You can merge this pull request into a Git repository by running: $ git pull https://github.com/fuyou001/incubator-rocketmq ROCKETMQ-277 Alternatively you can review and apply these changes as the patch at: https://github.com/apache/incubator-rocketmq/pull/157.patch To close this pull request, make a commit to your master/trunk branch with (at least) the following in the commit message: This closes #157 commit 5874ce3747a45250b7d77da3d716d92e09f70cd3 Author: å å²Date: 2017-08-24T09:24:44Z #ROCKETMQ-277# fix bug commit 8e1ae4cafbd52f529758a79e68176d27ad9a1441 Author: å å² Date: 2017-08-24T09:45:46Z #ROCKETMQ-277# fix bug & add unit test commit 32e63fdc1ad0856939e58c0beb5919b8d425b074 Author: å å² Date: 2017-08-28T02:45:46Z [ROCKETMQ-277] delete sys.out --- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---