简体   繁体   中英

Solr server unreachable from Java client after OS X sleep

I have a local development stack working well on my Mac laptop to match a production site. Everything runs at various ports on localhost:

  • Solr 6.5.1
  • Postgres
  • Spring Boot

Everything runs fine until I close the laptop. Then after opening up the laptop, the web app, which relies on Solr's Java client, cannot reach the Solr server anymore:

org.apache.solr.client.solrj.SolrServerException: No live SolrServers available to handle this request
...
Caused by: java.net.UnknownHostException: fe80: nodename nor servname provided, or not known
    at java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method) ~[?:1.8.0_162]
    at java.net.InetAddress$2.lookupAllHostAddr(InetAddress.java:928) ~[?:1.8.0_162]
    at java.net.InetAddress.getAddressesFromNameService(InetAddress.java:1323) ~[?:1.8.0_162]
    at java.net.InetAddress.getAllByName0(InetAddress.java:1276) ~[?:1.8.0_162]
    at java.net.InetAddress.getAllByName(InetAddress.java:1192) ~[?:1.8.0_162]
    at java.net.InetAddress.getAllByName(InetAddress.java:1126) ~[?:1.8.0_162]
    at org.apache.http.impl.conn.SystemDefaultDnsResolver.resolve(SystemDefaultDnsResolver.java:45) ~[httpclient-4.5.6.jar:4.5.6]
    at org.apache.http.impl.conn.DefaultClientConnectionOperator.resolveHostname(DefaultClientConnectionOperator.java:263) ~[httpclient-4.5.6.jar:4.5.6]

But I can still manually query the Solr server fine at localhost via curl or the web interface, even the exact same query works fine. And the connection to postgres is always fine no matter what. Just the Java client connection to solr fails.

This problem state persists through:

  • stopping and starting Spring Boot
  • stopping and starting Solr
  • restarting IDE
  • starting website via commandline
  • starting website via IDE
  • cycling all network interfaces via ifconfig ... down/up
  • any combination of the above

The only way to restore that connection is to reboot my machine. This problem has persisted across several laptops and versions of OS X over the years, but currently I'm on 10.13.6 high sierra.

My questions:

  1. is there a fix to prevent this problem from occurring
  2. is there at least a quicker way to restore connectivity without having to reboot machine

This blog post solved my problem https://thoeni.io/post/macos-sierra-java/

In essence, there seems to be a "host" of issues (couldn't let that pun go by!) around Java having a hard time resolving the local hostname in certain circumstances, and they're all solved by this easy fix:

  1. type the hostname command in your terminal to determine your hostname. Let's say the answer is YOUR-HOSTNAME.

  2. add or modify these entries in your /etc/hosts :

127.0.0.1 localhost YOUR-HOSTNAME ::1 localhost YOUR-HOSTNAME

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM