paketo-buildpacks / libjvm

A library and helper applications that form the basis for building the different Paketo-style JVM-providing buildpacks
Apache License 2.0
19 stars 20 forks source link

enhancement(link_local_dns.go): avoid occur runtime panic when the nameservers are empty. #393

Closed orange-guo closed 4 months ago

orange-guo commented 4 months ago

Summary

Use return to instead of runtime panic if there no nameservers are found in /etc/resolve.conf

In the following case, the nameservers are empty

The container uses the host network but the nameserver is empty in the host file

Use Cases

If nameservers are empty, no runtime panic

Checklist

linux-foundation-easycla[bot] commented 4 months ago

CLA Signed


The committers listed above are authorized under a signed CLA.

dmikusa commented 4 months ago

This looks reasonable to me.

When this case occurs, and you have no DNS servers (i.e. /etc/resolv.conf is empty), what happens in your app with regards to DNS? Do requests fails (I'm guessing)? Or is your app just not using DNS?

I'm mostly curious because this helper will set the following two config settings, which disable DNS caching in the JVM, and I'm wondering if it might still be a good idea to do this if that file is empty. Even if you have no DNS servers, if your app tried to resolve a DNS that would presumably fail and the JVM might cache that result (not 100% sure it caches failures, or just successes, I didn't look). Probably not a big deal either way, but thought I'd ask.

networkaddress.cache.ttl=0
networkaddress.cache.negative.ttl=0

Thanks!

orange-guo commented 4 months ago

The application is deployed into the on-prem environment in my case, so the application does not use DNS.

DNS is one of the ways to find a host

In Linux, /etc/nsswitch.conf is used to configure how the system finds a host, for example:

hosts: dns nis files

If the host is not found from the aforementioned sources, Java may throw an error similar to "Temporary failure in name resolution."

JVM parameters.

networkaddress.cache.ttl
networkaddress.cache.negative.ttl

These parameters are looks like the host caching parameters

In cases no DNS, the decision to disable caching may depend on the frequency of content changes in other host sources, such as (files, nis) in /etc/nsswitch.conf.
However, it is generally difficult to make assumptions about the frequency of these changes.
Therefore, I think that explicitly configuring to disable the cache might be a better approach.
This approach is ensure that the system does not rely on potentially outdated or incorrect information from other host sources.