I'm using commandbox-hostupdater for my local deve...
# box-products
s
I'm using commandbox-hostupdater for my local development servers. Almost every time I go to start a server I get the error
The IP address that [myhost.name] resolves to can't be bound.  If you ping it, does it point to a local network adapter?
In order to get the server running I have to manually open
/etc/hosts
and remove the prior entry. Is this a known issue or is something wrong with my configuration? MacOS, using CommandBox
5.9.0+00721
and hostupdater
1.9.2
b
What do you mean by "the prior entry"?
s
from a previous
server start
b
What happens when you ping myhost.name?
s
i.e., I can start a server one time and it works correctly.
But every subsequent time I have to first edit out the the entry from the prior start
b
There should be no need to remove old host file entries. At least not from other servers if that's what you mean.
s
But it's the same server?
b
Marcos is likely part of the issue. It required extra magic to work.
If there is already a host entry for the current server, then nothing should need to happen. It should already be ready to go.
s
Copy code
PING myhost.name (127.127.0.1): 56 data bytes
64 bytes from 127.127.0.1: icmp_seq=0 ttl=64 time=0.029 ms
64 bytes from 127.127.0.1: icmp_seq=1 ttl=64 time=0.210 ms
64 bytes from 127.127.0.1: icmp_seq=2 ttl=64 time=0.085 ms
64 bytes from 127.127.0.1: icmp_seq=3 ttl=64 time=0.254 ms
That's what I would think too. But I guess it tries to add the entry again, or doesn't "see" the existing entry?
b
Hmm, ping works but Java may be getting different result
If you look at the source for host updater, you can see there's some bash commands it runs on first go
Maybe your version of Mac OS needs those run every time?
s
I'll check it out.
b
I don't know what this does (I'm not a Mac user), but it basically runs
Copy code
ifconfig lo0 alias 127.127.x.x up
when adding a new IP address. I've had Mac users report that quit working after updating their system.
I'd start and see if that fixes the issue. If so, maybe we can make the module run it every time. If not, we'll troubleshoot elsewhere
s
ok
I can't find that error message in the source code. Where does it come from? Is commandbox echoing back something from the system?
b
What error message?
That happens when Java throws a
BindException
You can see if your host file entry binds in the CommandBox REPL like so
Copy code
createObject( "java", "java.net.InetAddress" ).getByName( 'myhost.name' ).toString()
That asks Java (via the OS) to find the address that the hostname is bound to
s
Yep that one. OK
b
Actually, I think a bad hostname throws
UnknownHostException
which is throws the error 2 lines above
You can mimic exactly what CommandBox does to test if a port/host is available to bind on with this code in the REPL
Copy code
createObject( "java", "java.net.ServerSocket" ).init( 8080, 1, createObject( "java", "java.net.InetAddress" ).getByName( '<http://site1.com|site1.com>' ) ).close()
where
<http://site1.com|site1.com>
is the hostname and
8080
is the port (replace as-necessary)
That code is basically throwing a
BindException
which causes the error you see.
The trick is to figure out what on earth your Mac is doing to ignore the host file entry when Java tries to bind on it
s
When I do
createObject( "java", "<http://java.net|java.net>.InetAddress" ).getByName( 'myhost.name' ).toString()
in the REPL I get:
Can't assign requested address (Bind failed)
And my server is running and responding on the hostname so I know the host file entry is there
so yeah, seems like the Java is not able to resolve it
b
Yep, if you try cache it in the REPL you can get better error messages
but basically, if java throws that, then we assume the host is no good
So trying that
ifconfig lo0 alias 127.127.x.x up
trick would be my first guess at what the issue may be
s
Not sure what you mean by "try to cache it" in the REPL
b
catch
I just spelled badly 🙂
Copy code
try{}catch( any e ) {}
Though actually, I forgot I enhanced the REPL recently to output more when the
verboseErrors
config setting is enabled.
s
ah
b
From my commends in the code, the bind exception usually means the IP address in question isn't bound to any local network adapter on that machine.
s
I'm not sure how all the binding works, but that is definitely not the case here. The IP is bound. I can ping it, and when the server is up I can access it via IP or hostname. So I think we need to figure out a better way to test that on MacOS. I noticed the last commit to the repo was from @elpete "elpete Get host updater working on Mac again" does he have this issue?
b
I think his issues were related to not using root and the sudo prompt not asking him for a password, but that was a while ago
If you can find out why Java can't bind to the IP, then we can try and work around it
Did you try the
ifconfig
command yet?
s
if I do
ifconfig lo0
the response is
Copy code
lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> mtu 16384
	options=1203<RXCSUM,TXCSUM,TXSTATUS,SW_TIMESTAMP>
	inet 127.0.0.1 netmask 0xff000000 
	inet6 ::1 prefixlen 128 
	inet6 fe80::1%lo0 prefixlen 64 scopeid 0x1 
	inet 127.127.0.7 netmask 0xff000000 
	inet 127.127.0.1 netmask 0xff000000 
	inet 127.127.0.2 netmask 0xff000000 
	nd6 options=201<PERFORMNUD,DAD>
those three 127.127 addresses are from servers I've got running, or previously had running
b
That doesn't really mean anything to me, lol
Without knowing what IP was assigned in the
hosts
file that isn't working
And my suggestion was to specifically run the
up
command that the hostupdater module runs the first time it puts an IP address in your hosts file.
e.g. • the next time you go to start a server and it fails to bind • grab the IP for that site which the hostupdater added to your
hosts
file • run that exactly same full ifconfig command • see if it makes any difference in Java being able to bind to it
s
Will do
Now of course I can't get it to reproduce 🤣
😢 1
I think I know why though. Because I ran server stop and that cleared the previous host entry.
ok, nope that wasn't it
b
Only forgetting the server should clear it