Typically, the root cause of this issue is that the host name is not resolvable to an IP address.
However, the process that GlassFish uses to check to see if a port is available is actually quite complicated, so there can be other reasons that this message is printed.
At a minimum, the message must be rewritten, as it is possible for it to be output when there isn't another process already using the admin port. The message must be more accurate about the possible reasons for the problem. The trick will be to make the message concise while also conveying the possible reasons.
Here is exactly what happens when the server is performing the check for which failure results in this message:
1. StartServerHelper.checkPorts calls StartServerHelper.adminPortInUse(), which calls StartServerHelper.adminPortInUse(addresses) where addresses is a list of admin host names and port numbers. By default, this is just one entry, localhost:4848.
2. adminPortInUse calls NetUtils.isPortFree on the host and port.
3. isPortFree checks to see if the port is a valid port number (4848 is)
4. isPortFree checks calls NetUtils.isThisMe to determine if this address represents an interface on this system. isThisMe makes a sequence of calls resulting in a call to InetAddress.getAllByName(InetAddress.getLocalHost().getHostName()). It calls this list myadds. Then it calls InetAddress.getAllByName(hostname) where hostname is "localhost" or whatever the admin host has been set to in the config and calls this list theiradds. isThisMe then looks at the theiradds list, and if any one of them is the loopback address (based on calling isLoopbackAddress) or if the address is in the myadds list, then true is returned. Otherwise false is returned.
5. Back in isPortFree, if isThisMe is true (which should be true for the default localhost:4848 case), it calls NetUtils.isPortFreeServer(port). Note that here the hostname is ignored. If isThisMe is false, then NetUtils.isPortFreeClient(host, port) is called.
6. NetUtils.isPortFreeServer(port) checks to see if the port is free on three addresses: 0.0.0.0, InetAddress.getLocalHost(), and InetAddress.getByName("localhost"). It does this by calling NetUtils.isPortFreeServer(host, port) for each of them. All have to be available for this test to pass.
7. NetUtils.isPortFreeServer(host, port) creates a ServerSocket (which internally does a bind on that socket). If that constructor throws an exception, the port is considered in use.
Normally, if a server is really running on the port, this process will fail in step 7, and the current message reflects that failure. But there are several other places in this process where it can fail, and the message will be output even though there is no server running.
The most typical case is in step 6, on the call to InetAddress.getLocalHost. If there is no entry for the hosts hostname in /etc/hosts or DNS lookup on the hostname fails, then this call with throw an UnknownHostException, and the isPortFreeServer check fails.
There are several questionable steps in this algorithm:
a) Why does isPortFree call isPortFreeServer(port) rather than isPortFreeServer(host, port)? If it called the latter, this would avoid the call to InetAddress.getLocalHost in step 6.
b) Why is StartServerHelper.adminPortInUse call isPortFree rather than isPortFreeServer(host, port), thereby bypassing the isThisMe call?