cdsap / Talaiot

Simple and extensible plugin to track task times in your Gradle Project.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

UnknownHostException

hram opened this issue · comments

My build failed with an exceptont:
Caused by: java.net.UnknownHostException: teamcity-new: teamcity-new: Name or service not known at io.github.cdsap.talaiot.metrics.HostnameMetric$1.invoke(SimpleMetrics.kt:76) at io.github.cdsap.talaiot.metrics.HostnameMetric$1.invoke(SimpleMetrics.kt:75) at io.github.cdsap.talaiot.metrics.base.Metric.get(Metric.kt:15) at io.github.cdsap.talaiot.provider.MetricsProvider.get(MetricsProvider.kt:45) at io.github.cdsap.talaiot.provider.MetricsProvider.get(MetricsProvider.kt:16) at io.github.cdsap.talaiot.publisher.TalaiotPublisherImpl.publish(TalaiotPublisherImpl.kt:42) at io.github.cdsap.talaiot.TalaiotListener.buildFinished(TalaiotListener.kt:76) at jdk.internal.reflect.GeneratedMethodAccessor656.invoke(Unknown Source) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:36) ... 92 more Caused by: java.net.UnknownHostException: teamcity-new: Name or service not known ... 102 more
talaiot version 1.5.1

This exception throws only on teamcity build agent.
I found discussion about this problem https://stackoverflow.com/questions/1881546/inetaddress-getlocalhost-throws-unknownhostexception and ask devops to configure build agent.
But in my case it is not always possible to configure build agent and this one maybe one of them.

Hi, thanks for the issue. I merged a quick fix to avoid the exception.
The StackOverflow link that you sent explains the issue:

It seems that InetAddress.getLocalHost() ignores the /etc/resolv.conf, but only looks at the /etc/hosts file (where I hadn't specified anything besides localhost)

Apparently we can rely on NetworkInterface.getNetworkInterfaces() as a fall back when InetAddress.getLocalHost() throws an UnknownHostException. In the initial fix I just catch the exception. I can deploy a new version in a couple days.