Outbound Link Summary:
13 years ago
p3k dots

TLDR: switch off Internet Sharing when running the H2 database server.

Yesterday, I got a strange error when trying to run an instance of the H2 database server:

java.net.ConnectException: Cannot allocate memory
	at java.net.PlainSocketImpl.socketConnect(Native Method)
	at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:351)
	at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:213)
	at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:200)
	at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:432)
	at java.net.Socket.connect(Socket.java:529)
	at org.h2.util.NetUtils.createSocket(NetUtils.java:110)
	at org.h2.util.NetUtils.createSocket(NetUtils.java:91)
	at org.h2.util.NetUtils.createLoopbackSocket(NetUtils.java:49)
	at org.h2.server.web.WebServer.isRunning(WebServer.java:354)
	at org.h2.tools.Server.isRunning(Server.java:415)
	at org.h2.tools.Server.start(Server.java:374)
	at org.h2.tools.Server.runTool(Server.java:215)
	at org.h2.tools.Server.main(Server.java:115)
The Web Console server could not be started. Possible cause: another server is already running at http://192.168.2.1:8082
Exception in thread "main" org.h2.jdbc.JdbcSQLException: Exception opening port "H2 Console Server (http://192.168.2.1:8082)" (port may be in use), cause: "timeout" [90061-157]
	at org.h2.message.DbException.getJdbcSQLException(DbException.java:327)
	at org.h2.message.DbException.get(DbException.java:167)
	at org.h2.tools.Server.start(Server.java:377)
	at org.h2.tools.Server.runTool(Server.java:215)
	at org.h2.tools.Server.main(Server.java:115)

Of course, there was and is no other server already running at that port. The “Cannot allocate memory” message was too disturbing, anyway.

I even got the very same error when trying to netcat the port:

$ nc -vz 192.168.2.1 8082 nc: connect to 192.168.2.1 port 8082 (tcp) failed: Cannot allocate memory

Searching for fixes only revealed one resource pointing to a possible fix. Unfortunately, that did not help – and reinstalling OS X was not an option at that point.

Even worse, I got the same pointers when asking for help in the H2 forum.

Almost desperately, I looked at the IP address again and finally noticed that it is not the usual one, only similar.

A look at the Sharing Preferences revealed that I got Internet Sharing running so I disabled it and instantly everything was working again!

(Still, the error message remains a mystery to me, though...)