Giter VIP home page Giter VIP logo

Comments (3)

osiegmar avatar osiegmar commented on June 5, 2024

Thanks for bringing this up!

It's very interesting, because according to the JavaDocs this should never happen, rather the method getCanonicalHostName() should return:

the fully qualified domain name for this IP address, or if the operation is not allowed by the security check, the textual representation of the IP address

Before changing any code, I'd like to understand the cause of this problem. Can you share some additional information about your operating system, java vendor and version and how your systems host name is configured?

from logback-gelf.

guxingke avatar guxingke commented on June 5, 2024

Thanks for your reply

Test Code

import java.net.InetAddress;
import java.util.*;

public class Test {
    public static void main(String[] args) throws Exception {
        InetAddress ia = InetAddress.getLocalHost();

        String name = ia.getCanonicalHostName();
        System.out.println(name);

        String hostname= ia.getHostName();
        System.out.println(hostname);
    }
}

Dev

java Test
image

uname -a
Darwin gxk.mini 18.2.0 Darwin Kernel Version 18.2.0: Thu Dec 20 20:46:53 PST 2018; root:xnu-4903.241.1~1/RELEASE_X86_64 x86_64

java -version
java version "1.8.0_202"
Java(TM) SE Runtime Environment (build 1.8.0_202-b08)
Java HotSpot(TM) 64-Bit Server VM (build 25.202-b08, mixed mode)

hostname
gxk.mini

ping `hostname` -c 1
PING gxk.mini (127.0.0.1): 56 data bytes
64 bytes from 127.0.0.1: icmp_seq=0 ttl=64 time=0.029 ms

--- gxk.mini ping statistics ---
1 packets transmitted, 1 packets received, 0.0% packet loss
round-trip min/avg/max/stddev = 0.029/0.029/0.029/0.000 ms

Prod

java Test
image

uname -a
Linux wp-app-2-51.duitang.cn 4.13.10-1.el7.elrepo.x86_64 #1 SMP Fri Oct 27 09:07:34 EDT 2017 x86_64 x86_64 x86_64 GNU/Linux

java -version
java version "1.8.0_144"
Java(TM) SE Runtime Environment (build 1.8.0_144-b01)
Java HotSpot(TM) 64-Bit Server VM (build 25.144-b01, mixed mode)

hostname
wp-app-2-51.duitang.cn

ping `hostname` -c 1
PING wp-app-2-51.duitang.cn (10.1.2.51) 56(84) bytes of data.
64 bytes from 10.1.2.51: icmp_seq=1 ttl=64 time=0.033 ms

--- wp-app-2-51.duitang.cn ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 0.033/0.033/0.033/0.000 ms

Note

  1. The Dev env works well. The Prod env get empty.
  2. the name ip mapping defined in the /etc/hosts
  3. no outer dns can resolve the hostname.

that's all, thanks, i don't want to dig into temporary.
if you want more info , i will provide.

from logback-gelf.

osiegmar avatar osiegmar commented on June 5, 2024

I've checked the code of java.net.InetAddress#getCanonicalHostName and I think that the only reason why this method could return an empty string (undocumented!) instead of a hostname or ip address is because of some nameserver misconfiguration or because of a JDK bug. Although, I couldn't find any related bug reports or discussions on the internet about this behavior. In Moocars implementation this is handled (by chance?) because the library is checking if the hostname contains . and is not an IP address (to detect if it is fully qualified). But that implementation does not support IPv6 and prefers java.net.InetAddress#getHostName() instead of the ip address that might be returned by java.net.InetAddress#getCanonicalHostName which might be ambiguous.

I fixed this issue by 187f2f9 and released 2.1.1.

from logback-gelf.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.