Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NetUtils.getLocalHostName() takes 30s #2098

Closed
dominik42 opened this issue Sep 17, 2021 · 2 comments · Fixed by #2134
Closed

NetUtils.getLocalHostName() takes 30s #2098

dominik42 opened this issue Sep 17, 2021 · 2 comments · Fixed by #2134

Comments

@dominik42
Copy link

dominik42 commented Sep 17, 2021

Environment

Liquibase Version: 4.3.5

Liquibase Integration & Version: maven

Liquibase Extension(s) & Version:

Database Vendor & Version:

Operating System Type & Version: MacOS 11.5.2 Big Sur

Description

During liquibase startup, the call database.getDefaultSchemaName(); in liquibase.changelog.ChangeLogParameters.java:61 leads to resolving the current hostname by liquibase.util.NetUtil.getLocalHostName in NetUtil.java:71. The subsequent line 75 takes 30s to resolve the hostname for the IP given by line 73. Interestingly, line 73 doesn't return 127.0.0.1 (from network interface eth0) but another IP taken from another network interface (eth1 / company internal network IP, here '/192.168.254.80' - yes starting with the slash. This IP can't resolved as fast as normally done by java vm.

liquibase.util.NetUtil.getLocalHostName()

InetAddress localhost = getLocalHost(); // => '/192.168.254.80' ... yes with the leading slash
if (localhost != null) {
    return localhost.getHostName(); // needs 30s
}

Expected/Desired Behavior

Same as normal JVM resolution, tested by the follwing:

    @Test
    void testResolveLocalhost() throws UnknownHostException {
        InetAddress ia = InetAddress.getLocalHost();
        String hostname = ia.getHostName(); // 6ms
    }

    @Test
    void testResolveLiquibase() throws UnknownHostException, SocketException {
        String ia = NetUtil.getLocalHostAddress(); //30s
    }

Additional Context

There are solution on Stackoverflow for the general host resolving problem in JVM. ( https://stackoverflow.com/questions/39636792/jvm-takes-a-long-time-to-resolve-ip-address-for-localhost/39698914#39698914 ) But the solutiuons given there didn't work.

@molivasdat molivasdat added this to To Do in Conditioning++ via automation Sep 24, 2021
@molivasdat
Copy link
Contributor

Thanks for the suggestion @dominik42 We will add this to the list of issues that we are processing.

@nvoxland nvoxland moved this from To Do to Code Review in Conditioning++ Dec 8, 2021
@suryaaki2 suryaaki2 moved this from Code Review to Ready for Handoff (In JIRA) in Conditioning++ Dec 8, 2021
@XDelphiGrl XDelphiGrl self-assigned this Feb 11, 2022
@kataggart kataggart removed this from Ready for Handoff (In JIRA) in Conditioning++ Aug 1, 2022
@kataggart kataggart added this to To Do in Conditioning++ via automation Aug 1, 2022
@kataggart kataggart removed this from To Do in Conditioning++ Sep 2, 2022
@eEQK
Copy link

eEQK commented Sep 19, 2022

In my case resolving was taking a lot of time because I had ZeroTier One running (p2p virtual network, works like Hamachi)

Simply disconnect from the virtual network and it should work quickly again

nvoxland added a commit that referenced this issue Oct 11, 2022
- Use default localhost finder for MacOs
- Removed specific check for windows/mac in NetUtil in favor of a more generic check for whether a loopback or local address got returned before falling back to iterating over interfaces
- Cached the found network interface to avoid future lookups

Co-authored-by: Nathan Voxland <nathan@voxland.net>
Co-authored-by: Daniel Mallorga <dmallorga@liquibase.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment