Bug #20041 not able to connect to mysql from tomcat after a prolonged interval
Submitted: 24 May 2006 11:17 Modified: 30 May 2006 19:06
Reporter: Aravind Raghavan Email Updates:
Status: Not a Bug Impact on me:
None 
Category:Connector / J Severity:S1 (Critical)
Version:mysql-connector-java-5.5.0-beta OS:Windows (Windows XP)
Assigned to: CPU Architecture:Any

[24 May 2006 11:17] Aravind Raghavan
Description:
I am using MySql5.0  &  mysqlconnector-java-5.5.0
 web container -  apache tomcat 5.5.9  (both web server & database are running in the same machine).
When I start the web server,  initially I am able to connect to mysql database.  but after a prolonged interval,  I start getting the following error.  further connection to the database is not possible unless I restart the web server.  

com.mysql.jdbc.CommunicationsException: Communications link failure due to under
lying exception:

** BEGIN NESTED EXCEPTION **

java.io.EOFException

STACKTRACE:

java.io.EOFException
        at com.mysql.jdbc.MysqlIO.readFully(MysqlIO.java:1865)
        at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:2256)
        at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2756)
        at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1536)
        at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1626)
        at com.mysql.jdbc.Connection.execSQL(Connection.java:3025)
        at com.mysql.jdbc.Connection.execSQL(Connection.java:2954)
        at com.mysql.jdbc.Statement.executeQuery(Statement.java:1009)
        at org.apache.tomcat.dbcp.dbcp.DelegatingStatement.executeQuery(Delegati
ngStatement.java:205)
        at loginServlet.login(loginServlet.java:102)
        at loginServlet.doPost(loginServlet.java:60)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
icationFilterChain.java:252)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
ilterChain.java:173)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperV
alve.java:213)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextV
alve.java:178)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.j
ava:126)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.j
ava:105)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineVal
ve.java:107)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.jav
a:148)
        at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java
:856)
        at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.proce
ssConnection(Http11Protocol.java:744)
        at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpo
int.java:527)
        at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFol
lowerWorkerThread.java:80)
        at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadP
ool.java:684)
        at java.lang.Thread.run(Thread.java:595)

** END NESTED EXCEPTION **

Last packet sent to the server was 5953 ms ago.

How to repeat:
Start the mysql database  & apache web server.   Try connecting to database, it will connect.    Dont make any further connection for prolonged period of time say 8 hrs.  Try connecting to database.  It will throw the above mentioned exception.
[30 May 2006 19:06] Mark Matthews
MySQL times out connections after 8 hours of inactivity. Either don't hold them open that long, or test connections for staleness with your connection pool.

More details in the manual:

http://dev.mysql.com/doc/refman/5.0/en/cj-faq.html