The OpenShift forums have been retired, but you can still read and search them.
For the most up-to-date information about how to use OpenShift please visit

MySQL DB stops responding after some time:

Hi there, i have a problem with my application's DB. i created a DIY container, pulled there an Apache tomcat installation from Git and deployed my project. then i created a cartage of MySQL on the same application container and copied there my tables. all works fine for about 8 hours and then MySQL DB stops responding. i have to: "rhc app restart" it in order to make it work again. does any one encounter this problem? Thanks for your help.

Best is to check for any error messages in the log files. It may shed some light on what led to failure. Here are instructions on how to check for logs:

After the restart of my application container the app is running fine, for now. I will update with logs if as soon as it stops working again. Thanks Sumana.

Well the problem is back, and here is the log from catalina.out:

==> diy-0.1/logs/catalina.out <== Dec 11, 2012 6:25:21 AM org.apache.catalina.core.StandardWrapperValve invoke SEVERE: Servlet.service() for servlet [jsp] in context with path [/coupons] thre w exception [org.hibernate.exception.JDBCConnectionException: could not execute query] with root cause Can not read response from server. Expected to read 4 byte s, read 0 bytes before connection was unexpectedly lost. at com.mysql.jdbc.MysqlIO.readFully( at com.mysql.jdbc.MysqlIO.reuseAndReadPacket( at com.mysql.jdbc.MysqlIO.reuseAndReadPacket( at com.mysql.jdbc.MysqlIO.checkErrorPacket( at com.mysql.jdbc.MysqlIO.sendCommand( at com.mysql.jdbc.MysqlIO.sqlQueryDirect( at com.mysql.jdbc.ConnectionImpl.execSQL( at com.mysql.jdbc.PreparedStatement.executeInternal( at com.mysql.jdbc.PreparedStatement.executeQuery( at org.hibernate.jdbc.AbstractBatcher.getResultSet( at org.hibernate.loader.Loader.getResultSet( at org.hibernate.loader.Loader.doQuery( at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections( at org.hibernate.loader.Loader.doList( at org.hibernate.loader.Loader.listIgnoreQueryCache( at org.hibernate.loader.Loader.list( at org.hibernate.loader.hql.QueryLoader.list( at org.hibernate.hql.ast.QueryTranslatorImpl.list( at org.hibernate.engine.query.HQLQueryPlan.performList( at org.hibernate.impl.SessionImpl.list( at org.hibernate.impl.QueryImpl.list( at com.eadesign.hibernate.HibernateCouponsDAO.findallCoupons( at com.eadesign.Assist.couponsToXmlDoc( at org.apache.jsp.Client.ajaxserverside_jsp._jspService( at org.apache.jasper.runtime.HttpJspBase.service( at javax.servlet.http.HttpServlet.service( at org.apache.jasper.servlet.JspServletWrapper.service( at org.apache.jasper.servlet.JspServlet.serviceJspFile( at org.apache.jasper.servlet.JspServlet.service( at javax.servlet.http.HttpServlet.service( at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter( at org.apache.catalina.core.ApplicationFilterChain.doFilter( at org.apache.catalina.core.StandardWrapperValve.invoke( at org.apache.catalina.core.StandardContextValve.invoke( at org.apache.catalina.authenticator.AuthenticatorBase.invoke( at org.apache.catalina.core.StandardHostValve.invoke( at org.apache.catalina.valves.ErrorReportValve.invoke( at org.apache.catalina.valves.AccessLogValve.invoke( at org.apache.catalina.core.StandardEngineValve.invoke( at org.apache.catalina.connector.CoyoteAdapter.service(

at org.apache.coyote.http11.AbstractHttp11Processor.process( at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process( at$ at java.util.concurrent.ThreadPoolExecutor.runWorker( at java.util.concurrent.ThreadPoolExecutor$ at

does anyone knows of this problem and how to fix it? Thanks again.

One suggestion, outside of what @ramr suggested (have your driver ping mysql), is to change the timeout settings. You can do so by accessing your mysql gear, and modifying: ~/mysql-5.1/etc/my.cnf

Here's a thread that shows what/how to modify it:


Hi Nam Duong, Thanks for your help. I don't know how to set up my driver to ping mysql. I did configured the timeouts using those two commands:

SET GLOBAL interactive_timeout = 180
SET GLOBAL wait_timeout = 180

and restarted the server, hope this will help. will update soon.

Sry for the misunderstanding. See mysql docs for details on those variables:

You'll need to set it higher than the default 8 hrs.


So if my application is not really that active and has a query or two a week, should i set it for a week length time? Thanks for the quick help.

@emil.adz, the connection will timeout on inactivity -- so you will probably need to use something like a connection pool
see: for more details.

Or alternatively, you could probably use the autoReconnect option for the MySQL JDBC connector.


Hi ramr, Thanks again for your help. i am not familiar with connection pool, i will read about it.

now for the autoReconnect option. this will be my next try in case the timeout configuration wont help me. so basically what i should do is in the hibernate.cfg.xml file i have to set:


as my connection url, of course the host will be my Openshift machine, but this is the way it's done?

Well, just to update you guys, changing the interactive_timeout and the wait_timeout parameter to high values (1 day) didn't helped me, neither the autoReconnect option for MySQL JDBC. i have add the c3p0 connection pool mechanism to my project to see maybe it will solve my problem. will update again in few days.

Thanks to all of you for your help.

Hi everyone, Looks like the c3p0 connection pool solved my problem. I didn't experience this error since then. Many thanks to you all for your help.

Thank you for the confirmation!

If you have some spare cycles, it would be a great help to the community if you added some code samples. Thanks for your time in advanced.

Actually I have written 3 guides regarding my last experiences with OpenShift, that can be found in my blog:

The posts are:

Guide: Introduction to Openshift hosting Apache Tomcat.

Guide: WordPress hosting on OpenShift.

Guide: c3p0 – JDBC3 Connection and Statement Pooling.

I will be glad if this helps someone other then my self.

Thank again for your help, Nam Duong.

@emil.adz, 8 hours is the default inactivity timeout in mysql.
You can run something like show variables like "%timeout" in mysql to verify
what the values for your env are (wait/interactive timeout values are in seconds).

Looks like your driver/client bits needs to be configured to send some
sorta heartbeat/keepalive message to keep the connection from idling.


Thank ramr,

this was the result from phpMyAdmin:


My client is a simple web application that allows user to see stores based on their location. the data in the DB is those stores. the application of course sits on the same container. can i do something locally on the server to keep the connection from idling?
setting the interactive_timeout and the wait_timeout to low values will fix my problem? do you know of any articles regarding this matter?

Thanks in advance.