I recently started using the excellent adm wrapper for the android debug bridge.
I quickly noticed that my app was hanging on startup on an aarch_64
(Apple M1) machine.
Fortunately, vert.x, a dependency of adm, gave the following warning:
[vertx-blocked-thread-checker] WARN io.vertx.core.impl.BlockedThreadChecker - Thread Thread[vert.x-eventloop-thread-0,5,main] has been blocked for 4985 ms, time limit is 2000 ms
io.vertx.core.VertxException: Thread blocked
Doing a local build of adm enabled me to configure vert.x to set its warningExceptionTime
to 1 second.
// For example:
private val vertx by lazy {
Vertx.vertx(VertxOptions().apply {
warningExceptionTime = TimeUnit.SECONDS.toNanos(1L)
})
}
After this, it additionally shared the stack trace:
at [email protected]/java.net.Inet4AddressImpl.lookupAllHostAddr(Native Method)
at [email protected]/java.net.InetAddress$PlatformNameService.lookupAllHostAddr(InetAddress.java:929)
at [email protected]/java.net.InetAddress.getAddressesFromNameService(InetAddress.java:1519)
at [email protected]/java.net.InetAddress$NameServiceAddresses.get(InetAddress.java:848)
at [email protected]/java.net.InetAddress.getAllByName0(InetAddress.java:1509)
at [email protected]/java.net.InetAddress.getLocalHost(InetAddress.java:1641)
This shows that InetAddress.getLocalHost()
is unable to figure out the address of my-macbookpro.local
and is sending out DNS queries to find it. Oof.
This quick test will show if you are affected: inetTester.
I am aware of three two ways to fix the problem.
Execute hostname
in a shell and put the result in your /etc/hosts
like so:
# Prevent poor java.net.InetAddress.getLocalHost from hanging.
127.0.0.1 your-macbookpro.local
::1 your-macbookpro.local
No. I don't think this works. At least I haven't gotten it to work.
Preferable to 1. for long-term fixes.
Create the directory /etc/resolver/
if it does not exist.
Create a new file /etc/resolver/local
and add your hostname info.
Start dnsmasq
.
Gloriously, you can do this. Simply run with
-Djdk.net.hosts.file=/path/to/hosts/file
You could construct that new file by copying /etc/hosts
and appending your hostname info.
This offers some flexibility by removing the need to update your users' /etc
files directly.