tudoutiao / h2database

Automatically exported from code.google.com/p/h2database
0 stars 0 forks source link

Under linux got always a port in use (include a fix) #173

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
When i start server under linux i got always a (port may be in use), but
however the server is up.

Debugging code:
Server.start() after start a service (TcpService) make a cycles to check if
server isRunning(false)
this call Server.isRunning(boolean) demand to service.isRunning(boolean)
proceding on call stack arrive to NetUtils.getBindAddress() where there is
the problem.

The bug is that in this method (NetUtils.getBindAddress) get a
SysProperties.BIND_ADDRESS that should be "*" instead is null, so this
method returns always null, call InetAddress.getByName(host) is never reach
so missing a return of the correct InetAddress object.

    private static InetAddress getBindAddress() throws UnknownHostException {
        String host = SysProperties.BIND_ADDRESS;
        if (host == null || host.length() == 0) {
            return null;
        }
        /* DEAD code host variable is always null */
        synchronized (NetUtils.class) {
            if (cachedBindAddress == null) {
                cachedBindAddress = InetAddress.getByName(host);
            }
        }
        return cachedBindAddress;
    }

Bug fix: correcting default value of BIND_ADDRESS in SysProperties as
specify in the javadoc work correctly ;) (better)
or remove check if (host == null), InetAddress.getByName(null) return the
same value of InetAddress.getByName("*")

Original issue reported on code.google.com by nikolas....@finantix.com on 4 Mar 2010 at 11:02

GoogleCodeExporter commented 8 years ago
little correction: InetAddress.getByName("*") does not work.
To work patch is modify check in NetUtils.getBindAddress()

if (host != null && host.length() == 0) {
    return null;
}

instead 
if (host == null || host.length() == 0) that return always null.

Original comment by nikolas....@finantix.com on 4 Mar 2010 at 12:38

GoogleCodeExporter commented 8 years ago
Hi,

Your patch is based on an older version of H2. Could you create a patch for the
current version? From what I see you changed getBindAddress, but I'm not sure.

Currently, getBindAddress() returns null by default. With your patch it returns 
InetAddress.getByName(null) - is that correct? As far as I understand the 
behavior
would change, because it would no longer create server sockets for all 
addresses, but
only for localhost, which is incorrect.

The real question is: why does the current code not work for you? It does work 
for
others, and it works for me (under Windows, Ubuntu, and Mac OS X). Do you know 
why it
doesn't work for you? Once we know why, we can try to find a solution. This 
solution
might be create a patch, or it might be throw a better error message.

Original comment by thomas.t...@gmail.com on 7 Mar 2010 at 11:23

GoogleCodeExporter commented 8 years ago
Setting the status for "works for me". I will re-open the issue when we have 
more
information.

Original comment by thomas.t...@gmail.com on 21 Mar 2010 at 11:33