在启动kafka生成器时,我在搜索dns条目(?)时遇到了超过4秒的非常奇怪的线程块,异常:
2019-02-11 10:00:33,982 WARN [vertx-blocked-thread-checker] io.vertx.core.impl.BlockedThreadChecker - Thread Thread[vert.x-eventloop-thread-0,5,main] has been blocked for 4172 ms, time limit is 1000 ms
io.vertx.core.VertxException: Thread blocked
at java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method)
at java.net.InetAddress$2.lookupAllHostAddr(InetAddress.java:929)
at java.net.InetAddress.getAddressesFromNameService(InetAddress.java:1324)
at java.net.InetAddress.getAllByName0(InetAddress.java:1277)
at java.net.InetAddress.getAllByName(InetAddress.java:1193)
at java.net.InetAddress.getAllByName(InetAddress.java:1127)
at java.net.InetAddress.getByName(InetAddress.java:1077)
at java.net.InetSocketAddress.<init>(InetSocketAddress.java:220)
at org.apache.kafka.clients.ClientUtils.parseAndValidateAddresses(ClientUtils.java:53)
at org.apache.kafka.clients.producer.KafkaProducer.<init>(KafkaProducer.java:406)
at org.apache.kafka.clients.producer.KafkaProducer.<init>(KafkaProducer.java:304)
它会发生一次(不是每次)我可以在vertx中以编程方式禁用ipv6查找吗?如何使此错误消失?
添加标志“-Djava.net.preferIPv4Stack = true”之后它解决了问题但是用InetAddress.getLocalHost()
打开了一些其他问题,返回localhost \ 127.0.0.1 for hostname \ ip ...解决这个问题我必须编辑/ etc / hosts在机器中:
# This file is automatically generated by our bootstrap script.
<MACHINE_IP> <MACHINE_HOSTNAME> # <-- Ordering ...
127.0.0.1 localhost
# The following lines are desirable for IPv6 capable hosts
# ::1 ip6-localhost ip6-loopback <MACHINE_HOSTNAME> <-- IPV6 must be disabled
从/ etc / hosts禁用所有IPv6部分后,解析了正确的主机名和IP,并正确启动了我的程序