Running bin/unet sim
or bin/unet audio
takes around 5 seconds before it opens the browser window.
Machine: MBP, macOS Mojave (10.14.6)
Looks like it takes time during opening the TCP listening ports. Logs below:
1569411423819|INFO|org.arl.unet.UnetBoot@1:invoke|fjage Build: fjage-1.6.1/10-09-2019_00:41:43
1569411423833|INFO|org.arl.unet.UnetBoot@1:invoke|UnetBoot: [samples/2-node-network.groovy]
1569411423936|INFO|org.arl.unet.JsonTypeAdapter@1:<clinit>|Groovy detected, using GroovyClassLoader
1569411423956|INFO|org.arl.fjage.remote.MessageAdapterFactory@1:<clinit>|Groovy detected, using GroovyClassLoader
1569411424383|INFO|org.arl.unet.sim.SimulationMasterContainer@1:openTcpServer|Listening on port 1101
1569411424472|INFO|Script1@1:invoke|Starting web interface on port null:8081
1569411424554|INFO|org.arl.fjage.connectors.WebServer@1:add|Adding web context: /fjage
1569411424555|INFO|org.arl.fjage.connectors.WebServer@1:add|Adding web context: /
1569411424559|INFO|org.arl.fjage.connectors.WebServer@1:add|Adding web context: /logs
1569411424559|INFO|org.arl.fjage.connectors.WebServer@1:add|Adding web context: /sim
1569411434392|INFO|org.arl.fjage.connectors.TcpServer@12:run|Listening on port 1101
>> [Comment] Here it hangs
1569411439397|INFO|org.arl.fjage.connectors.WebServer@1:add|Adding web context: /ws
1569411439440|INFO|org.arl.fjage.connectors.WebServer@1:start|Started web server on port 8081
1569411439443|INFO|org.arl.unet.sim.SimulationMasterContainer@1:addConnector|Listening on ws://172.23.155.178:8081/ws
1569411449455|INFO|org.arl.fjage.connectors.WebServer@1:add|Adding web context: /fjage/shell/ws
1569411449728|INFO|Script1@1:invoke|Created static node A (arp) @ [0, 0, -15]
1569411449729|INFO|org.arl.unet.sim.SimulationMasterContainer@1:openTcpServer|Listening on port 1102
1569411449730|INFO|Script1@1:invoke|Starting web interface on port null:8082
1569411449731|INFO|org.arl.fjage.connectors.WebServer@1:add|Adding web context: /fjage
1569411449732|INFO|org.arl.fjage.connectors.WebServer@1:add|Adding web context: /
1569411449732|INFO|org.arl.fjage.connectors.WebServer@1:add|Adding web context: /logs
1569411449732|INFO|org.arl.fjage.connectors.WebServer@1:add|Adding web context: /sim
1569411459738|INFO|org.arl.fjage.connectors.TcpServer@26:run|Listening on port 1102
>> [Comment] Here it hangs
1569411464739|INFO|org.arl.fjage.connectors.WebServer@1:add|Adding web context: /ws
1569411464742|INFO|org.arl.fjage.connectors.WebServer@1:start|Started web server on port 8082
1569411464742|INFO|org.arl.unet.sim.SimulationMasterContainer@1:addConnector|Listening on ws://172.23.155.178:8082/ws
1569411474754|INFO|org.arl.fjage.connectors.WebServer@1:add|Adding web context: /fjage/shell/ws
1569411474802|INFO|Script1@1:invoke|Created static node B (arp) @ [1000, 0, -15]
1569411474815|INFO|Script1@1:invoke| --- BEGIN SIMULATION #1 ---
It seems the TCPServer
class which is being opened when you start a new simulated node (at this place in the log)
1569411449729|INFO|org.arl.unet.sim.SimulationMasterContainer@1:openTcpServer|Listening on port 1102
seems to take almost five seconds to start. Once it's started, it prints this log
1569411459738|INFO|org.arl.fjage.connectors.TcpServer@26:run|Listening on port 1102
Relevant code is here https://github.com/org-arl/fjage/blob/master/src/main/java/org/arl/fjage/connectors/TcpServer.java#L71
Digging through it seems that Java's InetAddress.getLocalHost().getHostAddress()
is taking a long time.
This seems to be a common problem on macOS. See InetAddress.getLocalHost() slow to run (30+ seconds)
This tool can help you check if it indeed is an issue https://github.com/thoeni/inetTester
It seems that Java tries to do a DNS lookup on 127.0.0.1
before returning from getHostName
. And depending on your DNS settings, this could take up to 5 seconds to time out.
A simple fix that seems to work based on the Stackoverflow article linked above is to add an alias to your /etc/hosts
file for 127.0.0.1
.
This bash oneliner can do that for you.
n=$(sudo scutil --get LocalHostName); sudo sed -i.bak "/127.0.0.1/s/$/ $n/" /etc/hosts; sudo sed -i.bak "/::1/s/$/ $n/" /etc/hosts