Port is in use

410 views
Skip to first unread message

Markus

unread,
Mar 20, 2008, 12:08:24 PM3/20/08
to H2 Database
I recently attempted to upgrade my version of H2 from version 1.0.64
(2007-12-27) to 1.0.68 (2008-03-15), but ran into some problems.

I normally run H2 embedded, and after upgrading the server I could not
connect to it correctly (the jdbc-connector threw a connector is
broken-message). In order to debug, I tried to start the server by
itself.

"java -jar h2.jar" using 1.0.64 presented me with the following output
(from memory unfortunately, but I am fairly certain it is correct):
Port is in use, maybe another Web server already running on http://localhost:8082
Port is in use, maybe another TCP server already running on tcp://localhost:9092
Port is in use, maybe another PG server already running on pg://localhost:5435

At first I thought that I already had H2 running, but that was not the
case. After reverting to version 1.0.64, typing "java -jar h2.jar"
correctly started the database and further testing showed that the
embedded version worked once again.

I had however successfully been able to use org.h2.tools.RunScript to
migrate my database data from 1.0.64 to 1.0.68. Also, I did not have
this problem when attempting to run the database in Windows. The
system in question that I have the problem on runs OpenSuse and Java
1.6.0-b105.

Any help would be appreciated!

Thomas Mueller

unread,
Mar 23, 2008, 5:58:49 AM3/23/08
to h2-da...@googlegroups.com
Hi,

Could you enable the log when start the new version?

java org.h2.tools.Server -web -log true

This should print a stack trace with more information.

Regards,
Thomas

Markus

unread,
Mar 24, 2008, 9:08:10 AM3/24/08
to H2 Database
I already have a server running on the default ports, so I had to
switch the ports while doing this test. Unfortunately it provided me
with the same error and no further information. Is there a way for me
to get any more detailed information out of the server?

In any case, I received the following output.

"java -jar h2.jar org.h2.tools.Server -webPort 12345 -tcpPort 12346 -
pgPort 12347 -web -log true" using 1.0.68:

---

Port is in use, maybe another Web server already running on
https://localhost:12345
Port is in use, maybe another TCP server already running on tcp://localhost:12346
Port is in use, maybe another PG server already running on pg://localhost:12347

---

No further output was provided.

"java -jar h2.jar org.h2.tools.Server -webPort 12345 -tcpPort 12346 -
pgPort 12347 -web -log true" using 1.0.64:

---

org.h2.server.TcpServerThread@5488e2dd Connect
Connect
java.io.EOFException
at java.io.DataInputStream.readInt(DataInputStream.java:375)
at org.h2.server.pg.PgServerThread.process(PgServerThread.java:
132)
at org.h2.server.pg.PgServerThread.run(PgServerThread.java:75)
at java.lang.Thread.run(Thread.java:619)
java.io.EOFException
at java.io.DataInputStream.readInt(DataInputStream.java:375)
at org.h2.server.pg.PgServerThread.process(PgServerThread.java:
132)
at org.h2.server.pg.PgServerThread.run(PgServerThread.java:75)
at java.lang.Thread.run(Thread.java:619)
Disconnect
Close
Please open a browser and go to https://localhost:12345
org.h2.server.TcpServerThread@5488e2dd Disconnect
org.h2.server.TcpServerThread@5488e2dd Close

---

Thomas Mueller

unread,
Mar 25, 2008, 4:09:57 PM3/25/08
to h2-da...@googlegroups.com
Hi,

> "java -jar h2.jar org.h2.tools.Server -webPort 12345 -tcpPort 12346 -
> pgPort 12347 -web -log true"

When using -jar Java will not actually start Server but the Console.
Also you didn't add -tcp. Could you try again with:

java -cp h2.jar org.h2.tools.Server -tcpPort 12346 -tcp -log true

This will just start the TCP Server (to make it simpler). And if you
have time, could you run the H2 unit tests and post the result? It
will take about one hour. To start it, use 'ant test'.

Thanks,
Thomas

Markus

unread,
Mar 26, 2008, 12:42:52 PM3/26/08
to H2 Database
> This will just start the TCP Server (to make it simpler). And if you
> have time, could you run the H2 unit tests and post the result? It
> will take about one hour. To start it, use 'ant test'.

Ahh, sorry about that. I always mix up those options.

"java -cp h2.jar org.h2.tools.Server -tcpPort 12346 -tcp -log true"
produced the output:

---

org.h2.jdbc.JdbcSQLException: Connection is broken [90067-68]
at org.h2.message.Message.getSQLException(Message.java:91)
at org.h2.message.Message.getSQLException(Message.java:95)
at org.h2.message.Message.getSQLException(Message.java:73)
at org.h2.message.Message.getSQLException(Message.java:116)
at org.h2.tools.Server.start(Server.java:422)
at org.h2.tools.Server.run(Server.java:249)
at org.h2.tools.Server.main(Server.java:127)
Port is in use, maybe another TCP server already running on tcp://localhost:12346

---

I also ran the unit tests for the latest version. However, I could not
manage to get it to complete the unit tests. I tried it multiple times
with different memory settings (by adding -Xmx, -Xss and -
XX:MaxDirectMemorySize options as jvmarg:s to the Ant-target), but
eventually it always ran out of memory.

I have sent an mail to dbsupport at h2database.com with the ERROR.txt
file that was generated by the unit test along with the console
output. Is there anything more I can do to assist?

Thomas Mueller

unread,
Mar 28, 2008, 1:09:13 PM3/28/08
to h2-da...@googlegroups.com
Hi,

This looks like a networking problem of the system: The listener port
is opened, but it is not possible to connect to it. Unfortunately H2
doesn't print the right exception... Could you change the isRunning()
method of org.h2.server.TcpServer as follows and then try again using:
java org.h2.tools.Server -tcpPort 12346 -tcp -log true

public synchronized boolean isRunning() {
if (serverSocket == null) {
return false;
}
try {
Socket s = NetUtils.createLoopbackSocket(port, ssl);
s.close();
return true;
} catch (Exception e) {
traceError(e); // <<< new
return false;
}
}

Of course I will change this in the next release.
Thanks a lot for your help!

Regards,
Thomas

Thomas Mueller

unread,
Mar 28, 2008, 1:13:15 PM3/28/08
to h2-da...@googlegroups.com
Hi again,

Sorry, in the last version the method is called 'logError' not 'traceError'.

Regards,
Thomas

Markus

unread,
Mar 31, 2008, 7:20:19 AM3/31/08
to H2 Database
Sorry for the late reply and thanks for the work you put into this!

I downloaded the latest version of H2 (1.0.69 (2008-03-29)) and ran
"java -cp h2.jar org.h2.tools.Server -tcpPort 12346 -tcp -log true".
It did not appear as if I needed to alter the isRunning-method in the
latest version.

The following output was given:

---

java.net.SocketException: Network is unreachable
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:
333)
at
java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
at java.net.Socket.connect(Socket.java:519)
at java.net.Socket.connect(Socket.java:469)
at java.net.Socket.<init>(Socket.java:366)
at java.net.Socket.<init>(Socket.java:208)
at org.h2.util.NetUtils.createSocket(NetUtils.java:57)
at org.h2.util.NetUtils.createSocket(NetUtils.java:49)
at org.h2.util.NetUtils.createLoopbackSocket(NetUtils.java:33)
at org.h2.server.TcpServer.isRunning(TcpServer.java:232)
at org.h2.tools.Server.isRunning(Server.java:499)
at org.h2.tools.Server.start(Server.java:457)
at org.h2.tools.Server.run(Server.java:261)
at org.h2.tools.Server.main(Server.java:122)
org.h2.jdbc.JdbcSQLException: Connection is broken [90067-69]
at org.h2.message.Message.getSQLException(Message.java:91)
at org.h2.message.Message.getSQLException(Message.java:95)
at org.h2.message.Message.getSQLException(Message.java:73)
at org.h2.message.Message.getSQLException(Message.java:116)
at org.h2.tools.Server.start(Server.java:460)
at org.h2.tools.Server.run(Server.java:261)
at org.h2.tools.Server.main(Server.java:122)
Port is in use, maybe another TCP server already running on tcp://localhost:12346

---

It appears as if InetAddress.getLocalHost() retrieves an invalid
address, which I find to be very wierd. It is not pretty, but would it
be possible to add a method for substituting the address to localhost
manually?

Thomas Mueller

unread,
Apr 1, 2008, 1:28:43 PM4/1/08
to h2-da...@googlegroups.com
Hi,

This sounds like the process can not connect to the socket it opened.
Can you connect to this port? Maybe something with the networking
configuration is broken?
Can you start other tools that open a network socket, like Tomcat?

Regards,
Thomas

Markus

unread,
Apr 1, 2008, 6:37:12 PM4/1/08
to H2 Database
This probably depends on some network configuration, but for the life
of me I can not figure out where. It is not a general problem however.
As i mentioned earlier, I have no problems on the same machine when
using earlier versions of H2.

The problem comes from that the method InetAddress.getLocalHost(), for
some reason, does not produce a valid loopback address. I replaced

---

public static Socket createLoopbackSocket(int port, boolean ssl)
throws IOException {
InetAddress address = getBindAddress();
if (address == null) {
address = InetAddress.getLocalHost();
}
return createSocket(address.getHostAddress(), port, ssl);
}

---

in org.h2.util.NetUtils with

---

public static Socket createLoopbackSocket(int port, boolean ssl)
throws IOException {
InetAddress address = getBindAddress();
if (address == null) {
address = InetAddress.getByName("127.0.0.1");
}
return createSocket(address.getHostAddress(), port, ssl);
}

---

Despite being absolutely ridiculous, this solved the problem.

Thomas Mueller

unread,
Apr 4, 2008, 4:35:24 PM4/4/08
to h2-da...@googlegroups.com
Hi,

That's strange. What does this return for you?
java.net.InetAddress.getLocalHost().toString();

Regards,
Thomas

Yaroslav Kavenchuk

unread,
Apr 7, 2008, 6:56:21 AM4/7/08
to h2-da...@googlegroups.com
Thomas Mueller wrote:
> That's strange. What does this return for you?
> java.net.InetAddress.getLocalHost().toString();

stnt067/192.168.0.1

computer is in domain, MS Windows 2000 sp4

--
WBR, Yaroslav Kavenchuk.

Markus

unread,
Apr 8, 2008, 10:25:14 AM4/8/08
to H2 Database
Hi again and sorry for the late reply!

It turned out that I had an entry in my hosts-file that translated the
local hostname to an invalid local address. I read up a bit on how
java.net.InetAddress.getLocalHost() and it was definitely my mistake.
Sorry for bothering you with this! Hopefully the knowledge might be
useful for someone else.

Naresh Kumar Kakumani

unread,
Oct 16, 2017, 12:39:12 AM10/16/17
to H2 Database
Hello,

i have a scenario where i need to check if the tcpserver with a give port is already in use if so then stop the server and restart the same. 

Can i be able to do this, something like at the start of tcpserver i should check this and restart the server in that way i may not get port bind issues.

Thanks in advance,
Reply all
Reply to author
Forward
0 new messages