启动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查找吗? 如何使该错误消失?
答案 0 :(得分:0)
在添加标志“ -Djava.net.preferIPv4Stack = true”后,它解决了问题,但使用InetAddress.getLocalHost()
打开了其他一些问题,该问题返回localhost \ 127.0.0.1作为主机名\ 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已解析,并且我的程序正确启动