OutOfMemory when creating a connection to local TCP server

569 views
Skip to first unread message

alexg

unread,
Oct 18, 2009, 8:01:07 AM10/18/09
to H2 Database
This sample code runs into an OutOfMemoryError on my Mac with h2
database version 1.2.121
Is there another way to start a TCP-Server locally and connect it from
localhost and also from remote systems?

Class.forName("org.h2.Driver");
dbServer = Server.createTcpServer(new String[] {"-tcpAllowOthers", "-
baseDir", dbPath}).start();
connection = DriverManager.getConnection("jdbc:h2:tcp://localhost/
testDB","sa", "");

Stracktrace:
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
at org.h2.command.CommandRemote.prepare(CommandRemote.java:82)
at org.h2.command.CommandRemote.<init>(CommandRemote.java:48)
at org.h2.engine.SessionRemote.prepareCommand(SessionRemote.java:418)
at org.h2.engine.SessionRemote.upgradeClientVersionIfPossible
(SessionRemote.java:359)
at org.h2.engine.SessionRemote.connectServer(SessionRemote.java:352)
at org.h2.engine.SessionRemote.connectEmbeddedOrServer
(SessionRemote.java:229)
at org.h2.engine.SessionRemote.createSession(SessionRemote.java:223)
at org.h2.jdbc.JdbcConnection.<init>(JdbcConnection.java:110)
at org.h2.jdbc.JdbcConnection.<init>(JdbcConnection.java:94)
at org.h2.Driver.connect(Driver.java:58)
at java.sql.DriverManager.getConnection(DriverManager.java:582)
at java.sql.DriverManager.getConnection(DriverManager.java:185)
at rezeptSuite.service.db.SerDBHandler.initDBConnection
(SerDBHandler.java:72)
at rezeptSuite.control.ControlRezeptVerwaltung.start
(ControlRezeptVerwaltung.java:79)
at rezeptSuite.control.ControlRezeptVerwaltung.main
(ControlRezeptVerwaltung.java:173)

Thomas Mueller

unread,
Oct 22, 2009, 4:02:07 AM10/22/09
to h2-da...@googlegroups.com
Hi,

> This sample code runs into an OutOfMemoryError on my Mac with h2
> database version 1.2.121

Is it possible that you are running a very old version of H2 on the
server side? It looks like from the stack trace. However, that alone
doesn't seem to be the problem. Do you use a prepared statement with a
lot of parameters? Or do you have very little memory?

If this is reproducible, could you post a test case or describe what
you do exactly? It would be great if the test case does not have any
dependencies except the H2 jar file (that is, a simple SQL script that
can be run in the H2 Console, or a Java class uses the JDBC API and is
run using a static main method). Please include any initialization
code (CREATE TABLE, INSERT and so on) in the Java class or in a .sql
script file.

> Is there another way to start a TCP-Server locally and connect it from
> localhost and also from remote systems?

No, that's the correct way.

Regards,
Thomas

alexg

unread,
Oct 25, 2009, 12:37:19 PM10/25/09
to H2 Database
I have created a simple class with only one dependency to the latest
h2 version 1.2.121
My Mac has 2GB memory. This class runs in "java.lang.OutOfMemoryError:
Java heap space". There is not SQL statement.

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

import org.h2.tools.Server;


public class Test {

public static void main(String[] args) {
try {
Class.forName("org.h2.Driver");
Server dbServer = Server.createTcpServer(new String[] {"--
tcpAllowOthers", "-baseDir", "/Users/alexg/Documents/java/
testDB"}).start();
Connection connection = DriverManager.getConnection("jdbc:h2:tcp://
localhost/testDB",
//connection = DriverManager.getConnection("jdbc:h2:" + dbPath,
"sa", // username
"sa");
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}

Nikolay Gorylenko

unread,
Oct 25, 2009, 4:31:35 PM10/25/09
to h2-da...@googlegroups.com
Your Mac, even if it has 2Gb memory, still cannot think istead of you.
In short - add "-XX:MaxPermSize=256m" to your JAVA_OPTS

Neunerball

unread,
Oct 26, 2009, 3:21:03 PM10/26/09
to H2 Database
You could try using either of these tools to get more information on
what's causing the problem:
http://java.sun.com/javase/6/docs/technotes/tools/share/jhat.html
http://java.sun.com/developer/technicalArticles/Programming/HPROF.html

In general, the JVM's heap stores all objects created by an executing
Java program. Objects are created by Java's "new" operator, and memory
for new objects is allocated on the heap at run time.
Therefore, using the tools above you can find out what objects are in
the heap. If those objects are created by the H2 engine, send Thomas
the heap dump, since it will help him solving the problem.
If the object are created by your code, make sure you really need all
the objects at the same time, before using the option suggested by
Nikolay. Because, if your code is creating too many objects that
aren't released on time, sooner or later you will run into the
OutOfMemoryException again.

greetings,

Rolf

alexg

unread,
Oct 28, 2009, 4:11:19 PM10/28/09
to H2 Database
This parmater doesn't help. Tried also with -Xmx512m before. The same
class runs on my windows pc without problems.

On 25 Okt., 21:31, Nikolay Gorylenko <n0...@jug.ua> wrote:
> Your Mac, even if it has 2Gb memory, still cannot think istead of you.
> In short - add "-XX:MaxPermSize=256m" to your JAVA_OPTS
>
> Better - read this articlehttp://www.mkyong.com/tomcat/tomcat-javalangoutofmemoryerror-permgen-...

alexg

unread,
Oct 28, 2009, 4:44:45 PM10/28/09
to H2 Database
I think the problem is in the class CommandRemote in the line 73.

paramCount = transfer.readInt();

On my mac the variable paramCount was setted to 841839476. In the next
foreach block, h2 tries to create 841839476 ParameterRemote objects. I
think the problem is the local TCP server, creating a connection to a
remote (started on windows pc) tcp server works without problems.

On 26 Okt., 20:21, Neunerball <neunerb...@hotmail.com> wrote:
> You could try using either of these tools to get more information on
> what's causing the problem:http://java.sun.com/javase/6/docs/technotes/tools/share/jhat.htmlhttp://java.sun.com/developer/technicalArticles/Programming/HPROF.html

alexg

unread,
Oct 28, 2009, 5:24:32 PM10/28/09
to H2 Database
I think the problem is the Server, not the client. The server is not
running correctly. After debugging the server start process, i found
out that while starting the server a exception was thrown without
printing to console. e.printStackTrace() on the line 133 in the class
TCPServerThread shows following stacktrace:

java.io.EOFException
at java.io.DataInputStream.readInt(DataInputStream.java:375)
at org.h2.value.Transfer.readInt(Transfer.java:148)
at org.h2.server.TcpServerThread.run(TcpServerThread.java:69)
at java.lang.Thread.run(Thread.java:637)

On 22 Okt., 09:02, Thomas Mueller <thomas.tom.muel...@gmail.com>
wrote:

Thomas Mueller

unread,
Oct 30, 2009, 10:33:15 AM10/30/09
to h2-da...@googlegroups.com
Hi,

Is it possible that you are running a very old version of H2 on the

server side? What version of H2 do you use on the server side?

I can not reproduce this problem. Could you post a simple, standalone
test case that reproduces the problem? It would be great if the test


case does not have any dependencies except the H2 jar file (that is, a
simple SQL script that can be run in the H2 Console, or a Java class
uses the JDBC API and is run using a static main method). Please
include any initialization code (CREATE TABLE, INSERT and so on) in
the Java class or in a .sql script file.

Regards,
Thomas

alexg

unread,
Oct 30, 2009, 3:06:17 PM10/30/09
to H2 Database
Hi,
please read my postings before.

I have created a simple class with only one dependency to the latest
h2 version 1.2.121
My Mac has 2GB memory. This class runs in "java.lang.OutOfMemoryError:
Java heap space". There is not SQL statement.

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

import org.h2.tools.Server;

public class Test {

public static void main(String[] args) {
try {
Class.forName("org.h2.Driver");
Server dbServer = Server.createTcpServer(new
String[] {"-
tcpAllowOthers", "-baseDir", "/Users/alexg/Documents/java/
testDB"}).start();
Connection connection =
DriverManager.getConnection("jdbc:h2:tcp://
localhost/testDB",
//connection =
DriverManager.getConnection("jdbc:h2:" + dbPath,
"sa", //
username
"sa");
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

I cat reproduce the problem anytime on my mac. This code works on my
windows pc without problems.

On 30 Okt., 15:33, Thomas Mueller <thomas.tom.muel...@gmail.com>
wrote:

Neunerball

unread,
Nov 2, 2009, 11:43:59 AM11/2/09
to H2 Database
Your last statement (Mac vs. Windows) sounds more like a problem with
the JRE (JVM), rather than the H2.
I'd look for a newer Version of the JRE (JVM) @ http://developer.apple.com/java/download/
> > Thomas- Hide quoted text -
>
> - Show quoted text -

Thomas Mueller

unread,
Nov 2, 2009, 1:11:02 PM11/2/09
to h2-da...@googlegroups.com
Hi,

Are you running the code against an empty database? If not, could you
send me the testDB database?

Regards,
Thomas

alexg

unread,
Nov 3, 2009, 9:50:10 AM11/3/09
to H2 Database
Yes, the database does not exists. H2 does not creating the directory,
like on windows. This is not a permission problem.

When i am debugging h2 on windows, following exception is also thrown,
but h2 is running second time into the TcpServerThread.run() method.
Not so on Mac OS.

java.io.EOFException
at java.io.DataInputStream.readInt(DataInputStream.java:375)
at org.h2.value.Transfer.readInt(Transfer.java:148)
at org.h2.server.TcpServerThread.run(TcpServerThread.java:69)
at java.lang.Thread.run(Thread.java:637)

alexg

unread,
Nov 3, 2009, 9:50:14 AM11/3/09
to H2 Database
Im developing other applications with the same VM without problems. I
tried this with Java 5 and Java 6. Latest VM of both versions is
installed.

On 2 Nov., 17:43, Neunerball <neunerb...@hotmail.com> wrote:
> Your last statement (Mac vs. Windows) sounds more like a problem with
> the JRE (JVM), rather than the H2.
> I'd look for a newer Version of the JRE (JVM) @http://developer.apple.com/java/download/

Thomas Mueller

unread,
Nov 5, 2009, 3:16:05 PM11/5/09
to h2-da...@googlegroups.com
Hi,

My guess is that your have _two_ version of H2 in your classpath.
Could you verify this please?

I did run your your test case, but there was no error message or stack
trace. The test case doesn't actually do anything else than what the
H2 Console does, or what the unit tests do. Could you run the unit
tests on your system? Do to that, run ./build.sh test - see also
http://www.h2database.com/html/build.html#build_targets

Regards,
Thomas

alexg

unread,
Nov 6, 2009, 9:43:38 AM11/6/09
to H2 Database
OutOfMemoryError is also thrown by start h2 tcp-server from console,
after selecting "Generic H2 (Server)" in the Web-If and click on "test
connection".

alexgs-mac-mini-4:bin alexg$ sh h2.sh -trace -tcpAllowOthers -tcpPort
8085 -baseDir /Users/alexg/Documents/java/testDB
Exception in thread "H2 Console thread" java.lang.OutOfMemoryError:
Java heap space
at org.h2.command.CommandRemote.prepare(CommandRemote.java:82)
at org.h2.command.CommandRemote.<init>(CommandRemote.java:48)
at org.h2.engine.SessionRemote.prepareCommand(SessionRemote.java:418)
at org.h2.engine.SessionRemote.upgradeClientVersionIfPossible
(SessionRemote.java:359)
at org.h2.engine.SessionRemote.connectServer(SessionRemote.java:352)
at org.h2.engine.SessionRemote.connectEmbeddedOrServer
(SessionRemote.java:229)
at org.h2.engine.SessionRemote.createSession(SessionRemote.java:223)
at org.h2.jdbc.JdbcConnection.<init>(JdbcConnection.java:110)
at org.h2.jdbc.JdbcConnection.<init>(JdbcConnection.java:94)
at org.h2.Driver.connect(Driver.java:58)
at org.h2.server.web.WebServer.getConnection(WebServer.java:618)
at org.h2.server.web.WebThread.login(WebThread.java:1068)
at org.h2.server.web.WebThread.process(WebThread.java:418)
at org.h2.server.web.WebThread.processRequest(WebThread.java:183)
at org.h2.server.web.WebThread.process(WebThread.java:236)
at org.h2.server.web.WebThread.run(WebThread.java:193)

The tests before where created with eclipse and no other, older
versions of h2 in the classpath. The latest tests where plain eclipse
projects with no jars in the classpath, in the classpath was only the
h2 projection created from source.

alexg

unread,
Nov 6, 2009, 9:50:21 AM11/6/09
to H2 Database
Another test to start h2 from console. I think the server was not
started correctly, when i'm now try to create a connection,
OutOfMemoryError will be thrown.

alexgs-mac-mini-4:bin alexg$ java -jar h2-1.2.121.jar -trace -
tcpAllowOthers -baseDir /Users/alexg/Documents/java/testDB
Fri, 6 Nov 2009 14:46:39 GMT
org.h2.server.TcpServerThread@64ea66 Connect
Connect
Disconnect
Close
org.h2.server.TcpServerThread@64ea66 Disconnect
org.h2.server.TcpServerThread@64ea66 Close

Thomas Mueller

unread,
Nov 9, 2009, 3:17:17 PM11/9/09
to h2-da...@googlegroups.com
Hi,

Could you run the built-in test cases and then send the result? The
easiest way to do that is run:

./build.sh test

See also: http://www.h2database.com/html/build.html#build_targets

The output should start with:

Target: test
Deleting temp
Deleting docs
Compiling 545 classes
Copying 1 files to temp
Compiling 324 classes
Copying 16 files to temp
Running org.h2.build.doc.GenerateHelp
Javadoc
Loading source files for package org.h2.tools...
Constructing Javadoc information...
Zip temp/org/h2/util/data.zip (388 KB)
Running org.h2.test.TestAll
H2 1.2.123 (2009-11-08) @ 2009-11-09 21:14:59.814
Java 1.5.0_20-b02-315, Java HotSpot(TM) Client VM, Apple Inc.
Mac OS X, i386, 10.5.8, unknown, / : \n US en null MacRoman

Test pageStore jdk14 (792 KB used)
00:02.644 org.h2.test.db.TestScriptSimple
00:01.286 org.h2.test.db.TestScript
00:01.871 org.h2.test.db.TestBigResult
00:05.954 org.h2.test.db.TestCases
00:01.072 org.h2.test.db.TestCluster
00:01.203 org.h2.test.db.TestDeadlock
00:00.809 org.h2.test.db.TestFullText create FT: 176

It will run for about one hour. For your problem, it's probably enough
if you run it for 15 minutes however. Basically there should not be
many stack traces in the output.

Regards,
Thomas

alexg

unread,
Nov 10, 2009, 4:21:39 PM11/10/09
to H2 Database
Test results:
alexgs-mac-mini-4:h2 alexg$ sh build.sh test
Target: test
Deleting temp
Deleting docs
Compiling 543 classes
Copying 1 files to temp
Compiling 327 classes
Copying 19 files to temp
Running org.h2.build.doc.GenerateHelp
Javadoc
Loading source files for package org.h2.tools...
Constructing Javadoc information...
Zip temp/org/h2/util/data.zip (387 KB)
Running org.h2.test.TestAll
H2 1.2.121 (2009-10-11) @ 2009-11-10 19:29:10.073
Java 1.6.0_15-b03-219, Java HotSpot(TM) Client VM, Apple Inc.
Mac OS X, i386, 10.6.1, unknown, / : \n DE de null MacRoman

Test pageStore jdk14 (4760 KB used)
00:03.374 org.h2.test.db.TestScriptSimple
00:01.308 org.h2.test.db.TestScript
00:02.568 org.h2.test.db.TestBigResult
00:04.454 org.h2.test.db.TestCases
00:01.371 org.h2.test.db.TestCluster
00:01.384 org.h2.test.db.TestDeadlock
00:00.817 org.h2.test.db.TestFullText create FT: 309
00:04.888 org.h2.test.db.TestIndex
00:01.106 org.h2.test.db.TestLinkedTable
00:05.992 org.h2.test.db.TestLob
00:02.286 org.h2.test.db.TestMemoryUsage
00:00.441 org.h2.test.db.TestMultiThread
00:01.030 org.h2.test.db.TestMultiThreadedKernel
00:04.320 org.h2.test.db.TestOpenClose
00:03.176 org.h2.test.db.TestOptimizations
00:54.345 org.h2.test.db.TestOutOfMemory
.
.
everythin ok, until

00:01.064 org.h2.test.db.TestMultiThreadedKernel
ERROR: insert org.h2.jdbc.JdbcSQLException: Verbindung ist
unterbrochen
Connection is broken [90067-121] ------------------------------
org.h2.jdbc.JdbcSQLException: Verbindung ist unterbrochen
Connection is broken [90067-121]
at org.h2.message.Message.getSQLException(Message.java:106)
at org.h2.message.Message.getSQLException(Message.java:117)
at org.h2.message.Message.getSQLException(Message.java:76)
at org.h2.message.Message.getSQLException(Message.java:152)
at org.h2.engine.SessionRemote.checkClosed(SessionRemote.java:464)
at org.h2.engine.SessionRemote.connectServer(SessionRemote.java:343)
at org.h2.engine.SessionRemote.connectEmbeddedOrServer
(SessionRemote.java:229)
at org.h2.engine.SessionRemote.createSession(SessionRemote.java:223)
at org.h2.jdbc.JdbcConnection.<init>(JdbcConnection.java:110)
at org.h2.jdbc.JdbcConnection.<init>(JdbcConnection.java:94)
at org.h2.Driver.connect(Driver.java:58)
at java.sql.DriverManager.getConnection(DriverManager.java:582)
at java.sql.DriverManager.getConnection(DriverManager.java:185)
at org.h2.test.db.TestOpenClose$1.run(TestOpenClose.java:145)
this exception came very often
.
..
...
org.h2.jdbc.JdbcSQLException: Datenbank wird wahrscheinlich bereits
benutzt: Locked by another process. M?gliche L?sungen: alle
Verbindungen schliessen; Server Modus verwenden
Database may be already in use: Locked by another process. Possible
solutions: close all other connection(s); use the server mode
[90020-121]
at org.h2.message.Message.getSQLException(Message.java:106)
at org.h2.message.Message.getSQLException(Message.java:117)
at org.h2.message.Message.getSQLException(Message.java:76)
at org.h2.store.FileLock.getExceptionAlreadyInUse(FileLock.java:457)
at org.h2.store.FileLock.lockFile(FileLock.java:320)
at org.h2.store.FileLock.lock(FileLock.java:131)
at org.h2.test.TestBase.logError(TestBase.java:394)
at org.h2.test.db.TestOpenClose$1.run(TestOpenClose.java:153)

next test:

00:13.108 org.h2.test.db.TestOpenClose Expected: 1000 actual: 907
ERROR: FAIL java.lang.AssertionError: Expected: 1000 actual: 907
java.lang.AssertionError: Expected: 1000 actual: 907
------------------------------
java.lang.AssertionError: Expected: 1000 actual: 907
at org.h2.test.TestBase.fail(TestBase.java:375)
at org.h2.test.TestBase.assertEquals(TestBase.java:510)
at org.h2.test.db.TestOpenClose.testCase(TestOpenClose.java:168)
at org.h2.test.db.TestOpenClose.test(TestOpenClose.java:40)
at org.h2.test.TestBase.runTest(TestBase.java:118)
at org.h2.test.TestAll.test(TestAll.java:504)
at org.h2.test.TestAll.runTests(TestAll.java:443)
at org.h2.test.TestAll.run(TestAll.java:354)
at org.h2.test.TestAll.main(TestAll.java:285)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke
(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke
(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.h2.build.BuildBase.invoke(BuildBase.java:203)
at org.h2.build.BuildBase.java(BuildBase.java:762)
at org.h2.build.Build.test(Build.java:503)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke
(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke
(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.h2.build.BuildBase.invoke(BuildBase.java:203)
at org.h2.build.BuildBase.run(BuildBase.java:193)
at org.h2.build.Build.main(Build.java:31)

Thomas Mueller

unread,
Nov 13, 2009, 11:44:30 AM11/13/09
to h2-da...@googlegroups.com
Hi,

I'm not sure, but it could be a network problem. Could you run the
following statement and post the result?

./build.sh testNetwork

In my case, I get:

----------------------
Target: testNetwork
environment settings:
awt.nativeDoubleBuffering=true
awt.toolkit=apple.awt.CToolkit
file.encoding=MacRoman
file.encoding.pkg=sun.io
file.separator=/
ftp.nonProxyHosts=local|*.local|169.254/16|*.169.254/16
gopherProxySet=false
http.nonProxyHosts=local|*.local|169.254/16|*.169.254/16
...
java.class.path=bin:/System/Library/Frameworks/JavaVM.framework/Home/lib/tools.jar:temp
java.class.version=49.0
java.endorsed.dirs=/System/Library/Frameworks/JavaVM.framework/Versions/1.5.0/Home/lib/endorsed
java.ext.dirs=/Library/Java/Extensions:/System/Library/Java/Extensions:/System/Library/Frameworks/JavaVM.framework/Versions/1.5.0/Home/lib/ext
java.home=/System/Library/Frameworks/JavaVM.framework/Versions/1.5.0/Home
...
java.library.path=.:/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java
java.runtime.name=Java(TM) 2 Runtime Environment, Standard Edition
java.runtime.version=1.5.0_20-b02-315
java.specification.name=Java Platform API Specification
java.specification.vendor=Sun Microsystems Inc.
java.specification.version=1.5
java.vendor=Apple Inc.
java.vendor.url=http://www.apple.com/
java.vendor.url.bug=http://bugreport.apple.com/
java.version=1.5.0_20
java.vm.info=mixed mode, sharing
java.vm.name=Java HotSpot(TM) Client VM
java.vm.specification.name=Java Virtual Machine Specification
java.vm.specification.vendor=Sun Microsystems Inc.
java.vm.specification.version=1.0
java.vm.vendor=Apple Inc.
java.vm.version=1.5.0_20-141
...
mrj.version=1050.1.5.0_20-315
os.arch=i386
os.name=Mac OS X
os.version=10.5.8
path.separator=:
...
sun.arch.data.model=32
sun.boot.class.path=/System/Library/Frameworks/JavaVM.framework/Versions/1.5.0/Classes/jsfd.jar:/System/Library/Frameworks/JavaVM.framework/Versions/1.5.0/Classes/classes.jar:/System/Library/Frameworks/JavaVM.framework/Versions/1.5.0/Classes/ui.jar:/System/Library/Frameworks/JavaVM.framework/Versions/1.5.0/Classes/laf.jar:/System/Library/Frameworks/JavaVM.framework/Versions/1.5.0/Classes/sunrsasign.jar:/System/Library/Frameworks/JavaVM.framework/Versions/1.5.0/Classes/jsse.jar:/System/Library/Frameworks/JavaVM.framework/Versions/1.5.0/Classes/jce.jar:/System/Library/Frameworks/JavaVM.framework/Versions/1.5.0/Classes/charsets.jar
sun.boot.library.path=/System/Library/Frameworks/JavaVM.framework/Versions/1.5.0/Libraries
sun.cpu.endian=little
sun.cpu.isalist=
sun.io.unicode.encoding=UnicodeLittle
sun.java.launcher=SUN_STANDARD
sun.jnu.encoding=MacRoman
sun.management.compiler=HotSpot Client Compiler
sun.os.patch.level=unknown
user.country=US
...
user.language=en
user.name=tmueller
user.timezone=

localhost:localhost/127.0.0.1
localhost/127.0.0.1
localhost/0:0:0:0:0:0:0:1
localhost/fe80:0:0:0:0:0:0:1%1
getLocalHost:BSLM-MAC-012.local/192.168.0.103
/192.168.0.103
byName:/192.168.0.103
ServerSocket[addr=0.0.0.0/0.0.0.0,port=0,localport=64923]
server accepting
client:/192.168.0.103:64923
server accepted:Socket[addr=/192.168.0.103,port=64924,localport=64923]
client:Socket[addr=/192.168.0.103,port=64923,localport=64924]
server read:123
client read:234
done
Done in 1437 ms
server closing
server done
----------------------

Regards,
Thomas
> --~--~---------~--~----~------------~-------~--~----~
> You received this message because you are subscribed to the Google Groups "H2 Database" group.
> To post to this group, send email to h2-da...@googlegroups.com
> To unsubscribe from this group, send email to h2-database...@googlegroups.com
> For more options, visit this group at http://groups.google.com/group/h2-database?hl=en
> -~----------~----~----~----~------~----~------~--~---
>
>

alexg

unread,
Nov 13, 2009, 11:52:23 AM11/13/09
to H2 Database
alexgs-mac-mini-4:h2 alexg$ sh build.sh testNetwork
Target: testNetwork
environment settings:
awt.nativeDoubleBuffering=true
awt.toolkit=apple.awt.CToolkit
file.encoding=MacRoman
file.encoding.pkg=sun.io
file.separator=/
ftp.nonProxyHosts=local|*.local|169.254/16|*.169.254/16
gopherProxySet=false
http.nonProxyHosts=local|*.local|169.254/16|*.169.254/16
java.awt.graphicsenv=apple.awt.CGraphicsEnvironment
java.awt.printerjob=apple.awt.CPrinterJob
java.class.path=bin:/System/Library/Frameworks/JavaVM.framework/Home/
lib/tools.jar:temp
java.class.version=50.0
java.endorsed.dirs=/System/Library/Frameworks/JavaVM.framework/
Versions/1.6.0/Home/lib/endorsed
java.ext.dirs=/Library/Java/Extensions:/System/Library/Java/
Extensions:/System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/
Home/lib/ext
java.home=/System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/
Home
java.io.tmpdir=/var/folders/P6/P6y60mINFpmPtzgh9U34sE+++TI/-Tmp-/
java.library.path=.:/Library/Java/Extensions:/System/Library/Java/
Extensions:/usr/lib/java
java.runtime.name=Java(TM) SE Runtime Environment
java.runtime.version=1.6.0_15-b03-219
java.specification.name=Java Platform API Specification
java.specification.vendor=Sun Microsystems Inc.
java.specification.version=1.6
java.vendor=Apple Inc.
java.vendor.url=http://www.apple.com/
java.vendor.url.bug=http://bugreport.apple.com/
java.version=1.6.0_15
java.vm.info=mixed mode
java.vm.name=Java HotSpot(TM) Client VM
java.vm.specification.name=Java Virtual Machine Specification
java.vm.specification.vendor=Sun Microsystems Inc.
java.vm.specification.version=1.0
java.vm.vendor=Apple Inc.
java.vm.version=14.1-b02-90
line.separator=

mrj.version=1060.1.6.0_15-219
os.arch=i386
os.name=Mac OS X
os.version=10.6.1
path.separator=:
socksNonProxyHosts=local|*.local|169.254/16|*.169.254/16
sun.arch.data.model=32
sun.boot.class.path=/System/Library/Frameworks/JavaVM.framework/
Versions/1.6.0/Classes/jsfd.jar:/System/Library/Frameworks/
JavaVM.framework/Versions/1.6.0/Classes/classes.jar:/System/Library/
Frameworks/JavaVM.framework/Frameworks/JavaRuntimeSupport.framework/
Resources/Java/JavaRuntimeSupport.jar:/System/Library/Frameworks/
JavaVM.framework/Versions/1.6.0/Classes/ui.jar:/System/Library/
Frameworks/JavaVM.framework/Versions/1.6.0/Classes/laf.jar:/System/
Library/Frameworks/JavaVM.framework/Versions/1.6.0/Classes/
sunrsasign.jar:/System/Library/Frameworks/JavaVM.framework/Versions/
1.6.0/Classes/jsse.jar:/System/Library/Frameworks/JavaVM.framework/
Versions/1.6.0/Classes/jce.jar:/System/Library/Frameworks/
JavaVM.framework/Versions/1.6.0/Classes/charsets.jar
sun.boot.library.path=/System/Library/Frameworks/JavaVM.framework/
Versions/1.6.0/Libraries
sun.cpu.endian=little
sun.cpu.isalist=
sun.io.unicode.encoding=UnicodeLittle
sun.java.launcher=SUN_STANDARD
sun.jnu.encoding=MacRoman
sun.management.compiler=HotSpot Client Compiler
sun.os.patch.level=unknown
user.country=DE
user.dir=/Users/alexg/Downloads/h2
user.home=/Users/alexg
user.language=de
user.name=alexg
user.timezone=

localhost:localhost/127.0.0.1
localhost/127.0.0.1
localhost/0:0:0:0:0:0:0:1
localhost/fe80:0:0:0:0:0:0:1%1
getLocalHost:alexgs-mac-mini-4.local/192.168.1.109
/192.168.1.109
byName:/192.168.1.109
ServerSocket[addr=0.0.0.0/0.0.0.0,port=0,localport=56212]
server accepting
client:/192.168.1.109:56212
server accepted:Socket[addr=/192.168.1.109,port=56213,localport=56212]
client:Socket[addr=/192.168.1.109,port=56212,localport=56213]
server read:123
client read:234
done
Done in 1493 ms
server closing
server done

Thomas Mueller

unread,
Nov 13, 2009, 12:17:18 PM11/13/09
to h2-da...@googlegroups.com
Hi,

Thanks! Everything looks fine... What the problem could be in theory
is that some old version of H2 is in the classpath. I wrote a special
test case, it is here:

http://h2database.com/p.html#5f581743f9ad5d4683f3ab6561474af5

Could you download this file, safe it as TestServer.java, and then
compile and run it? Please provide the exact statement you run and the
output. I get:

javac -cp h2-1.2.121.jar;. TestServer.java
java -cp h2-1.2.121.jar:. TestServer
Version ------------------
build: 2009-10-11
version: 1.2.121 (2009-10-11)
Processed: C:\data\h2database\h2web-20091026\h2\bin\testDB.h2.db
Memory ------------------
used: 1694
free: 1703
max: 66650112
Deleting old database ------------------
Processed: C:\data\h2database\h2web-20091026\h2\bin\testDB.h2.db
Trying to connect without server ------------------
Error trying to connect - expected
org.h2.jdbc.JdbcSQLException: Verbindung ist unterbrochen
Connection is broken [90067-121]
at org.h2.message.Message.getSQLException(Message.java:106)
at org.h2.message.Message.getSQLException(Message.java:117)
at org.h2.message.Message.getSQLException(Message.java:76)
at org.h2.message.Message.getSQLException(Message.java:152)
at org.h2.engine.SessionRemote.checkClosed(SessionRemote.java:464)
at org.h2.engine.SessionRemote.connectServer(SessionRemote.java:343)
at org.h2.engine.SessionRemote.connectEmbeddedOrServer(SessionRemote.java:229)
at org.h2.engine.SessionRemote.createSession(SessionRemote.java:223)
at org.h2.jdbc.JdbcConnection.<init>(JdbcConnection.java:110)
at org.h2.jdbc.JdbcConnection.<init>(JdbcConnection.java:94)
at org.h2.Driver.connect(Driver.java:58)
at java.sql.DriverManager.getConnection(DriverManager.java:525)
at java.sql.DriverManager.getConnection(DriverManager.java:171)
at TestServer.main(TestServer.java:29)
Starting server ------------------
Connecting ------------------
Creating a table ------------------
Closing ------------------
Stopping ------------------
Done ------------------

Regards,
Thomas
> --
>
> You received this message because you are subscribed to the Google Groups "H2 Database" group.
> To post to this group, send email to h2-da...@googlegroups.com.
> To unsubscribe from this group, send email to h2-database...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/h2-database?hl=.
>
>
>

alexg

unread,
Nov 13, 2009, 1:34:44 PM11/13/09
to H2 Database
alexgs-mac-mini-4:h2 alexg$ javac -cp ./bin/h2-1.2.121.jar
TestServer.java
alexgs-mac-mini-4:h2 alexg$ java -cp ./bin/h2-1.2.121.jar:. TestServer
Version ------------------
build: 2009-10-11
version: 1.2.121 (2009-10-11)
No database files have been found in directory . for the database
testDB
Memory ------------------
used: 1827
free: 61429
max: 65011712
Deleting old database ------------------
Processed: /Users/alexg/Downloads/h2/testDB.h2.db
Trying to connect without server ------------------
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
at org.h2.command.CommandRemote.prepare(CommandRemote.java:82)
at org.h2.command.CommandRemote.<init>(CommandRemote.java:48)
at org.h2.engine.SessionRemote.prepareCommand(SessionRemote.java:418)
at org.h2.engine.SessionRemote.upgradeClientVersionIfPossible
(SessionRemote.java:359)
at org.h2.engine.SessionRemote.connectServer(SessionRemote.java:352)
at org.h2.engine.SessionRemote.connectEmbeddedOrServer
(SessionRemote.java:229)
at org.h2.engine.SessionRemote.createSession(SessionRemote.java:223)
at org.h2.jdbc.JdbcConnection.<init>(JdbcConnection.java:110)
at org.h2.jdbc.JdbcConnection.<init>(JdbcConnection.java:94)
at org.h2.Driver.connect(Driver.java:58)
at java.sql.DriverManager.getConnection(DriverManager.java:582)
at java.sql.DriverManager.getConnection(DriverManager.java:185)
at TestServer.main(TestServer.java:29)

Thomas Mueller

unread,
Nov 14, 2009, 5:33:20 AM11/14/09
to h2-da...@googlegroups.com
Hi,

Did you start the H2 server before running the test? If yes, please
stop it first and then re-run the test? If you didn't start the H2
server before running the test, it looks like another kind of 'server'
(not an H2 TCP server) is already running on this port. Reason: the
out of memory exception occurred before the H2 server was started. You
could verify no other server is running on port 9092 (the default H2
server port), or change the port number in the test case (both for the
server and the client)?

The H2 JDBC client doesn't currently detect if it's talking to another
kind of server (HTTP server or so). I will add a basic detection
mechanism.

Regards,
Thomas

alexg

unread,
Nov 14, 2009, 6:27:42 AM11/14/09
to H2 Database
I had not started the server before. I had only started the test
class. Changing the port results the same exception.

As you can see, your test-case is dropping out in the method
"checkClosed". The method checkClosed is calling the method isClosed.
The method isClosed ruturns in my case false, because the transferList
contains one Transfer-object. This Transfer-object was created because
after this statement "String[] servers = StringUtils.arraySplit
(server, ',', true);" the servers variable contains one String object
"localhost".

Thomas Mueller

unread,
Nov 14, 2009, 8:33:04 AM11/14/09
to h2-da...@googlegroups.com
Hi,

> I had not started the server before. I had only started the test class.

If you didn't start a server, then the first connection attempt _must_
fail. Because in the first connection attempt, the H2 server is not
running. If the first connection attempt didn't result in "Connection
is broken", then another sever must be running on that port. In your
case, you got another exception, that means the client could connect
to a server (what kind of server I don't know, maybe an HTTP server,
maybe iTunes, maybe some kind of firewall).

> Changing the port results the same exception.

How did you change the port?

Could you run the following on the command line:

telnet localhost 9092

You should get:

Trying ::1...
telnet: connect to address ::1: Connection refused
Trying fe80::1...
telnet: connect to address fe80::1: Connection refused
Trying 127.0.0.1...
telnet: connect to address 127.0.0.1: Connection refused
telnet: Unable to connect to remote host

If you get another result, then another server is listening on this port.

Regards,
Thomas

alexg

unread,
Nov 14, 2009, 5:10:14 PM11/14/09
to H2 Database
It works now with port 8096. Unfortunately i cant see the blocking
process of port 9092. Netstat on MacOS delivers following result
tcp4 0 0 127.0.0.1.9092 *.*
LISTEN

I had installed Snow Lepoart 6 weeks ago, i dont know which process
could block this port. I think it would be better to warn the user,
when the port is already used by another process, an OutOfMemoryError
does not lead to a blocking port. It was not easy to identify this
problem.

Thank you for helping.

Thomas Mueller

unread,
Nov 16, 2009, 1:23:37 PM11/16/09
to h2-da...@googlegroups.com
Hi,

Thanks for your help! This problem was really hard to identify... I
have changed the JDBC client so it detects if the server is not in
fact an H2 server, so such problems will throw a "better" exception.
An OutOfMemory error is just weird.

> I think it would be better to warn the user,
> when the port is already used by another process

Can you still start a server on this port, even thought another server
is already started in this port? That would be really strange, but I
guess it's possible. On my system, I get the following exception if I
try to start the H2 Console twice:

The Web server could not be started. Possible cause: another server is
already running on http://192.168.0.102:8082
Root cause: Exception opening port "8082" (port may be in use), cause:
"java.net.BindException: Address already in use" [90061-123]
The TCP server could not be started. Possible cause: another server is
already running on tcp://192.168.0.102:9092
Root cause: Exception opening port "9092" (port may be in use), cause:
"java.net.BindException: Address already in use" [90061-123]
The PG server could not be started. Possible cause: another server is
already running on pg://192.168.0.102:5435
Root cause: Exception opening port "5435" (port may be in use), cause:
"java.net.BindException: Address already in use" [90061-123]
Exception in thread "main" org.h2.jdbc.JdbcSQLException: Exception
opening port "8082" (port may be in use), cause:
"java.net.BindException: Address already in use" [90061-123]
at org.h2.message.Message.getSQLException(Message.java:111)
at org.h2.util.NetUtils.createServerSocketTry(NetUtils.java:161)
at org.h2.util.NetUtils.createServerSocket(NetUtils.java:127)
at org.h2.server.web.WebServer.start(WebServer.java:300)
at org.h2.tools.Server.start(Server.java:347)
at org.h2.tools.Console.run(Console.java:146)
at org.h2.tools.Console.main(Console.java:91)
Caused by: java.net.BindException: Address already in use
at java.net.PlainSocketImpl.socketBind(Native Method)
at java.net.PlainSocketImpl.bind(PlainSocketImpl.java:359)
at java.net.ServerSocket.bind(ServerSocket.java:319)
at java.net.ServerSocket.<init>(ServerSocket.java:185)
at java.net.ServerSocket.<init>(ServerSocket.java:97)
at org.h2.util.NetUtils.createServerSocketTry(NetUtils.java:157)
... 5 more

If that's not the case for you, I could add some code to detect if
there is a listener on the port _before_ starting the listener.

Regards,
Thomas
Reply all
Reply to author
Forward
0 new messages