Getting error after upgrading to H2 DB 1.4.200 from 1.4.199 and deploying on Tomcat 9.x

1,135 views
Skip to first unread message

Balamurali Krishna Ippili

unread,
Mar 19, 2021, 7:03:52 AM3/19/21
to H2 Database
Hi Team,

I have upgraded my h2DB jar from 1.4.199 to 1.4.200 and when deploying it on Tomcat 9.0.44 it was giving the following error:

This is not the case with h2 DB version 1.4.199.

How can I solve this? Any pointers?

WARNING [main] org.apache.catalina.loader.WebappClassLoaderBase.clearReferencesThreads The web application [ca-nim-sm_h2DB] appears to have started a thread named [H2 TCP Server (tcp://10.230.44.99:55171)] but has failed to stop it. This is very likely to create a memory leak. Stack trace of thread:
 java.net.DualStackPlainSocketImpl.accept0(Native Method)
 java.net.DualStackPlainSocketImpl.socketAccept(DualStackPlainSocketImpl.java:131)
 java.net.AbstractPlainSocketImpl.accept(AbstractPlainSocketImpl.java:409)
 java.net.PlainSocketImpl.accept(PlainSocketImpl.java:199)
 java.net.ServerSocket.implAccept(ServerSocket.java:560)
 java.net.ServerSocket.accept(ServerSocket.java:528)
 org.h2.server.TcpServer.listen(TcpServer.java:263)
 org.h2.tools.Server.run(Server.java:610)
 java.lang.Thread.run(Thread.java:748)


Thanks,
Balamurali

This electronic communication and the information and any files transmitted with it, or attached to it, are confidential and are intended solely for the use of the individual or entity to whom it is addressed and may contain information that is confidential, legally privileged, protected by privacy laws, or otherwise restricted from disclosure to anyone else. If you are not the intended recipient or the person responsible for delivering the e-mail to the intended recipient, you are hereby notified that any use, copying, distributing, dissemination, forwarding, printing, or copying of this e-mail is strictly prohibited. If you received this e-mail in error, please return the e-mail to the sender, delete it from your computer, and destroy any printed copy of it.

Balamurali Krishna Ippili

unread,
Mar 23, 2021, 1:19:17 AM3/23/21
to H2 Database
Hello Team,

Are there any pointers on how to resolve the issue?

I am giving the problem description again here:


I have upgraded my h2DB jar from 1.4.199 to 1.4.200 and when deploying it on Tomcat 9.0.44 it was giving the following error:

This is not the case with h2 DB version 1.4.199.

How can I solve this? Any pointers?

WARNING [main] org.apache.catalina.loader.WebappClassLoaderBase.clearReferencesThreads The web application [ca-nim-sm_h2DB] appears to have started a thread named [H2 TCP Server (tcp://10.230.44.99:55171)] but has failed to stop it. This is very likely to create a memory leak. Stack trace of thread:
 java.net.DualStackPlainSocketImpl.accept0(Native Method)


Thanks,
Balamurali

Evgenij Ryazanov

unread,
Mar 23, 2021, 2:39:38 AM3/23/21
to H2 Database
Hello.

Your application shouldn't normally start TCP server of H2. If you need it, it should be launched as a separate process outside of your web / application server or at least in its process, but not on the web application level.

Maybe you accidentally added AUTO_SERVER to JDBC URL of H2?

Also if you use and embedded database and H2 is in the classpath of your application (not the best idea, but in many cases there is no other choice), you need to call the SHUTDOWN command explicitly from ServletContextListener.contextDestroyed().

Balamurali Krishna Ippili

unread,
May 5, 2021, 9:36:03 AM5/5/21
to H2 Database
Hi Evgenij ,

Thanks for your reply. I am really sorry for getting back to you very late due to other priorities. 

Yes we are using the following command to initialize the H2DB in our project. and it is working fine with h2-1.4.199.jar but with h2-1.4.200 version it was giving the issue. 

Following is my command:  jdbc:h2:%base%data\nim-sm-customizations;AUTO_SERVER=TRUE


Multiple processes can access the same database without having to start the server manually. To do that, append ;AUTO_SERVER=TRUE to the database URL. You can use the same database URL independent of whether the database is already open or not. This feature doesn't work with in-memory databases. Example database URL:

jdbc:h2:/data/test;AUTO_SERVER=TRUE

I am suspecting If we have removed the AUTO_SERVER=TRUE might cause other issues while accessing with multiple processes.So please suggest on this.

Also what is the difference between the H2DB versions 1.4.199 and 1.4.200?



Thanks,
Balamurali

--
You received this message because you are subscribed to the Google Groups "H2 Database" group.
To unsubscribe from this group and stop receiving emails from it, send an email to h2-database...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/h2-database/038663cd-2535-4c7a-8f67-3cb9947d40acn%40googlegroups.com.

Evgenij Ryazanov

unread,
May 5, 2021, 10:06:10 AM5/5/21
to H2 Database
Hello.

Don't use AUTO_SERVER in web applications, their lifecycle is different from standalone applications. Web applications should either use an embedded database or connections to a separate H2 Server process.

Balamurali Krishna Ippili

unread,
May 11, 2021, 3:58:30 AM5/11/21
to H2 Database
Hi Evgenij,

If the AUTO_SERVER=TRUE has been removed , can the external applications still be able to access the DB?



Thanks,
Balamurali

On Wed, May 5, 2021 at 7:36 PM Evgenij Ryazanov <kat...@gmail.com> wrote:
Hello.

Don't use AUTO_SERVER in web applications, their lifecycle is different from standalone applications. Web applications should either use an embedded database or connections to a separate H2 Server process.

--
You received this message because you are subscribed to the Google Groups "H2 Database" group.
To unsubscribe from this group and stop receiving emails from it, send an email to h2-database...@googlegroups.com.

Balamurali Krishna Ippili

unread,
May 11, 2021, 4:05:42 AM5/11/21
to H2 Database
Hi Evgenij,

One more thing is that the following is my application's H2 DB URL:

jdbc:h2:%base%data\nim-sm-customizations;AUTO_SERVER=TRUE

And with the h2 jar version 1.4.199 I couldn't see any issues even if the URL contains  AUTO_SERVER=TRUE  but with 1.4.200 only it was giving an error below:

WARNING [main] org.apache.catalina.loader.WebappClassLoaderBase.clearReferencesThreads The web application [ca-nim-sm_h2DB] appears to have started a thread named [H2 TCP Server (tcp://10.230.44.99:55171)] but has failed to stop it. This is very likely to create a memory leak. Stack trace of thread:
 java.net.DualStackPlainSocketImpl.accept0(Native Method)


Can we find any documentation that shows the differences between the versions 1.4.199 and 1.4.200 to understand what has been changed?


Thanks,
Balamurali

Balamurali Krishna Ippili

unread,
May 17, 2021, 2:54:21 AM5/17/21
to H2 Database
HI  Evgenij and Team,

Can someone help me on upgrading H2DB from 1.4.199 to 1.4.200?

We are forming the JDBC URL like this : jdbc:h2:%base%data\nim-sm-customizations;AUTO_SERVER=TRUE 

 And it is working fine with h2DB jar version 1.4.199 but with 1.4.200 (only 1 version difference) it was throwing an error saying below:


WARNING [main] org.apache.catalina.loader.WebappClassLoaderBase.clearReferencesThreads The web application [ca-nim-sm_h2DB] appears to have started a thread named [H2 TCP Server (tcp://10.230.44.99:55171)] but has failed to stop it. This is very likely to create a memory leak. Stack trace of thread:
 java.net.DualStackPlainSocketImpl.accept0(Native Method)
 java.net.DualStackPlainSocketImpl.socketAccept(DualStackPlainSocketImpl.java:131)
 java.net.AbstractPlainSocketImpl.accept(AbstractPlainSocketImpl.java:409)
 java.net.PlainSocketImpl.accept(PlainSocketImpl.java:199)
 java.net.ServerSocket.implAccept(ServerSocket.java:560)
 java.net.ServerSocket.accept(ServerSocket.java:528)
 org.h2.server.TcpServer.listen(TcpServer.java:263)
 org.h2.tools.Server.run(Server.java:610)
 java.lang.Thread.run(Thread.java:748)
  

For this I have removed the AUTO_SERVER=TRUE from the JDBC URL mentioned above and the error is not occurring while deploying my web application on Tomcat, however I am getting the below error in the tomcat longs and also unable to access my application UI.

17-May-2021 11:27:25.401 INFO [Thread-4] org.apache.catalina.core.ApplicationContext.log SessionListener: contextDestroyed()
17-May-2021 11:27:25.401 INFO [Thread-4] org.apache.catalina.core.ApplicationContext.log ContextListener: contextDestroyed()
17-May-2021 11:27:52.562 SEVERE [main] org.apache.catalina.core.StandardContext.listenerStart Exception sending context initialized event to listener instance of class [com.ca.integration.normalization.common.NIMServletContextListener]
java.lang.RuntimeException: NIM Application Persistence could not be initialized, application startup failed with error : General error: "java.lang.IllegalStateException: Unable to read the page at position 1924162229955 [1.4.200/6]" [50000-200]
at com.ca.integration.normalization.common.NIMServletContextListener.initializePersistence(NIMServletContextListener.java:567)
at com.ca.integration.normalization.common.NIMServletContextListener.initializeNIMWithDbDatastore(NIMServletContextListener.java:188)
at com.ca.integration.normalization.common.NIMServletContextListener.contextInitialized(NIMServletContextListener.java:127)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4716)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5177)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:717)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:690)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:706)
at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:1023)
at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1903)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75)


This is a bit urgent so could someone help me to resolve the issue?


Thanks,
Balamurali

Evgenij Ryazanov

unread,
May 17, 2021, 6:33:52 AM5/17/21
to H2 Database
Hello.

1. H2 is a small database engine and doesn't have an automatic upgrade procedure for database files. Unfortunately, latest releases also didn't mark their files as incompatible with older versions, so if you tried to open a database file created by one version in another it may lead to database corruption. In some cases these files can still be opened by the old version, but if you can open them, you should export the file to SQL immediately and create a new database with that SQL. The next version of H2 will mark its files as incompatible with older versions explicitly to avoid such issues.

The normal upgrade procedure for H2 is SCRIPT TO 'filename.sql' with the OLD version, creation of a new database file with the NEW version and execution of RUNSCRIPT FROM 'filename.sql' in it.

If you use the same database file in multiple applications, make sure they all have the same version of H2.

2. Unfortunately, 1.4.200 has some storage problems, it is less reliable than 1.4.199 in that area and may potentially corrupt database file by itself in some cases.

If you have a backup copy, just use it. If it was created by another version, use SCRIPT / RUNSCRIPT to copy data to the new database.

If you don't have it, you can try to use the recover tool:
If database file was somehow used by different versions of H2, you may want to try the all (but make a copy of existing corrupted file and use a new copy for each experiment for more safety).

Your application normally should invoke the online backup command from time to time:

Balamurali Krishna Ippili

unread,
May 17, 2021, 7:22:09 AM5/17/21
to H2 Database
Hi  Evgenij ,

Thanks for your quick response. Really appreciate it.

I am using h2db an internal DB using the following command  jdbc:h2:%base%data\nim-sm-customizations;AUTO_SERVER=TRUE and it will create the  nim-sm-customizations.mv file dynamically. This will happen with every deployment of our web application and the db file and data will be created afresh.  So here I am not using/reading/writing from any old database which was created with older versions of h2DB jar.


1. First I will create the  nim-sm-customizations.mv file under data folder
2. I will run some scripts which will insert the default data that is required to work with the application.



My example scripts will be like below:


drop table if exists nim_entity_types;
create table nim_entity_types(
id int auto_increment,
entity_type varchar(40),
description varchar(255),
last_modified_dt datetime default sysdate,
primary key(entity_type)
);

insert into nim_entity_types (id, entity_type, description) values (1,'incident','CA NIM incident');
insert into nim_entity_types (id, entity_type, description) values (2,'request','CA NIM request');
insert into nim_entity_types (id, entity_type, description) values (3,'attachment','CA NIM attachment');
insert into nim_entity_types (id, entity_type, description) values (4,'comment','CA NIM comment');
insert into nim_entity_types (id, entity_type, description) values (5,'change','CA NIM change');
insert into nim_entity_types (id, entity_type, description) values (6,'problem','CA NIM problem');
insert into nim_entity_types (id, entity_type, description) values (7,'ticket','CA NIM ticket');
insert into nim_entity_types (id, entity_type, description) values (8,'user','CA NIM user');
insert into nim_entity_types (id, entity_type, description) values (9,'group','CA NIM group');
insert into nim_entity_types (id, entity_type, description) values (10,'Relationship-ci','CA NIM Relationship for CI');
insert into nim_entity_types (id, entity_type, description) values (11,'Relationship-ticket','CA NIM Relationship for Ticket');

After executing these scripts on server start up it will insert some data into the h2DB file (which is created afresh) which is a required data for accessing our application GUI.


So could you please provide any pointers on the same and let me know if there are any changes needed in the scripts?



Thanks,
Balamurali

--
You received this message because you are subscribed to the Google Groups "H2 Database" group.
To unsubscribe from this group and stop receiving emails from it, send an email to h2-database...@googlegroups.com.

Balamurali Krishna Ippili

unread,
May 18, 2021, 1:08:17 AM5/18/21
to H2 Database
Hi  Evgenij  and Team ,

Is there any suggestion that should be followed?

Let me know if you need any demo to see my issue so we can have a webex?



Thanks,
Balamurali

Balamurali Krishna Ippili

unread,
May 20, 2021, 3:47:01 AM5/20/21
to H2 Database
Hi  Evgenij  and Team ,

Any pointers on this?


Thanks,
Balamurali

Evgenij Ryazanov

unread,
May 23, 2021, 12:45:40 AM5/23/21
to H2 Database
Hello.

First of all you need to ensure that your tools and your web application really use the same version of H2 and a new database file is created, in some cases build systems may fetch an unexpected version. And it would be much safer not to use AUTO_SERVER anywhere.

If H2 is in classpath of your web application, you need to execute the SHUTDOWN from the lifecycle listener of you application during its unload, otherwise there is a risk that database will not be properly closed.

If some version of H2 doesn't work for you, try tome other. 1.4.200 is actually less reliable than 1.4.199. You can also compile H2 from the current sources if you need some new features and can't use 1.4.199 and older versions.

You can also use the standalone TCP server of H2 instead of embedded databases. Remote databases aren't affected that much by various problems of their clients.
Reply all
Reply to author
Forward
0 new messages