5

I have records in /etc/hosts file which contains IPv4 and IPv6 addresses for host-name.com But I sometimes get UnknownHostException like:

redis.clients.jedis.exceptions.JedisConnectionException: java.net.UnknownHostException: host-name.com 
  at redis.clients.jedis.Connection.connect(Connection.java:137) 
  at redis.clients.jedis.BinaryClient.connect(BinaryClient.java:65) 
  at redis.clients.jedis.BinaryJedis.connect(BinaryJedis.java:1706) 
  at redis.clients.jedis.JedisFactory.makeObject(JedisFactory.java:28) 
  at org.apache.commons.pool.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:1188) 
  at redis.clients.util.Pool.getResource(Pool.java:38) 
    ... 2 common frames omitted 
Caused by: java.net.UnknownHostException: host-name.com 
  at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:178) 
  at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392) 
  at java.net.Socket.connect(Socket.java:579) 
  at redis.clients.jedis.Connection.connect(Connection.java:132) 
    ... 7 common frames omitted

How it's possible and how can I solve it?

  • Linux 3.2 (Debian stable) with unscd
  • java 1.7.0_45 with -Djava.net.preferIPv4Stack=true
  • /etc/nsswitch.conf has line hosts: files dns
  • /etc/hosts permissions -rw-r--r--
valodzka
  • 5,535
  • 4
  • 39
  • 50
  • "sometimes" : does it mean that it does work sometimes, but not at other times with the same hostname? – Ingo Nov 19 '13 at 16:56
  • yes, it mostly works (something like 99% of cases), but sometimes fail with same hostname – valodzka Nov 19 '13 at 18:05
  • Try disconnecting your computer from the network and seeing if you get an `UnknownHostException` then. – Robin Green Nov 19 '13 at 21:40
  • When computer is disconnected i'm getting `java.net.SocketException: Network is unreachable` – valodzka Nov 20 '13 at 04:53
  • 5
    Okay, dunno why this question is closed, BUT I had exactly the same case and the answer is: your file descriptor limit is exceeded (or almost exceeded). System fails to read the hosts file since it needs a free file descriptor to open it. Unfortunately, the UnknownHostException exception is misleading. When I replaced hostname with an IP address, I started to get "Too many open files". – Deinlandel Jan 29 '14 at 11:00
  • @Deinlandel Thank you, you are likely correct. I had problem with file descriptors limit at same time and was not able to connect two events. – valodzka Jan 29 '14 at 11:12

0 Answers0