title: MYSQL resetting the connection
body: <p>I am using CAS 3.4.5 on Apache tomcat 6 webserver with backend being mysql 5.1.37.
  I am connecting from CAS which is written in Java spring framework to Backend using mysql-jdbc-connector version 5.12.</p>
  
  <p>Intermittently the mysql is closing the persistent connection which CAS requires. Is there a way by which this could be avoided. Any ideas could be really appreciated. </p>
  
  <p>I am pasting the error which CAS receives when mysql resets the connection.</p>
  
  <pre><code>org.apache.catalina.core.StandardWrapperValve invoke
  SEVERE: Servlet.service() for servlet cas threw exception
  java.net.SocketException: Connection reset
          at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:96)
          at java.net.SocketOutputStream.write(SocketOutputStream.java:136)
          at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:65)
          at java.io.BufferedOutputStream.flush(BufferedOutputStream.java:123)
          at com.mysql.jdbc.MysqlIO.send(MysqlIO.java:3298)
          at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1941)
          at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2114)
          at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2696)
          at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2105)
          at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:2264)
          at org.apache.commons.dbcp.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:96)
          at org.apache.commons.dbcp.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:96)
          at org.springframework.jdbc.core.JdbcTemplate$1.doInPreparedStatement(JdbcTemplate.java:643)
          at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:586)
          at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:636)
          at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:665)
          at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:673)
          at org.springframework.jdbc.core.JdbcTemplate.queryForObject(JdbcTemplate.java:728)
          at org.springframework.jdbc.core.JdbcTemplate.queryForObject(JdbcTemplate.java:744)
          at org.springframework.jdbc.core.simple.SimpleJdbcTemplate.queryForObject(SimpleJdbcTemplate.java:143)
          at org.jasig.cas.adaptors.jdbc.QueryDatabaseAuthenticationHandler.authenticateUsernamePasswordInternal(QueryDatabaseAuthenticationHandler.java:38)
          at org.jasig.cas.authentication.handler.support.AbstractUsernamePasswordAuthenticationHandler.doAuthentication(AbstractUsernamePasswordAuthenticationHandler.java:58)
          at org.jasig.cas.authentication.handler.support.AbstractPreAndPostProcessingAuthenticationHandler.authenticate_aroundBody2(AbstractPreAndPostProcessingAuthenticationHandler.java:72)
          at org.jasig.cas.authentication.handler.support.AbstractPreAndPostProcessingAuthenticationHandler.authenticate_aroundBody3$advice(AbstractPreAndPostProcessingAuthenticationHandler.java:44)
          at org.jasig.cas.authentication.handler.support.AbstractPreAndPostProcessingAuthenticationHandler.authenticate(AbstractPreAndPostProcessingAuthenticationHandler.java:1)
          at org.jasig.cas.authentication.AuthenticationManagerImpl.authenticateAndObtainPrincipal(AuthenticationManagerImpl.java:78)
          at org.jasig.cas.authentication.AbstractAuthenticationManager.authenticate_aroundBody0(AbstractAuthenticationManager.java:42)
          at org.jasig.cas.authentication.AbstractAuthenticationManager.authenticate_aroundBody1$advice(AbstractAuthenticationManager.java:44)
          at org.jasig.cas.authentication.AbstractAuthenticationManager.authenticate(AbstractAuthenticationManager.java:1)
          at org.jasig.cas.CentralAuthenticationServiceImpl.createTicketGrantingTicket_aroundBody10(CentralAuthenticationServiceImpl.java:413)
          at org.jasig.cas.CentralAuthenticationServiceImpl.createTicketGrantingTicket_aroundBody11$advice(CentralAuthenticationServiceImpl.java:44)
          at org.jasig.cas.CentralAuthenticationServiceImpl.createTicketGrantingTicket(CentralAuthenticationServiceImpl.java:1)
          at sun.reflect.GeneratedMethodAccessor67.invoke(Unknown Source)
          at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
          at java.lang.reflect.Method.invoke(Method.java:597)
          at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:309)
          at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
          at org.springframework.aop.aspectj.MethodInvocationProceedingJoinPoint.proceed(MethodInvocationProceedingJoinPoint.java:80)
          at org.perf4j.aop.AbstractTimingAspect.doPerfLogging(AbstractTimingAspect.java:71)
          at sun.reflect.GeneratedMethodAccessor44.invoke(Unknown Source)
          at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
          at java.lang.reflect.Method.invoke(Method.java:597)
          at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethodWithGivenArgs(AbstractAspectJAdvice.java:621)
          at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethod(AbstractAspectJAdvice.java:610)
          at org.springframework.aop.aspectj.AspectJAroundAdvice.invoke(AspectJAroundAdvice.java:65)
          at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:161)
          at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:89)
          at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
          at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
          at $Proxy26.createTicketGrantingTicket(Unknown Source)
          at org.jasig.cas.web.flow.AuthenticationViaFormAction.submit_aroundBody2(AuthenticationViaFormAction.java:85)
          at org.jasig.cas.web.flow.AuthenticationViaFormAction.submit_aroundBody3$advice(AuthenticationViaFormAction.java:44)
          at org.jasig.cas.web.flow.AuthenticationViaFormAction.submit(AuthenticationViaFormAction.java:1)
          at sun.reflect.GeneratedMethodAccessor66.invoke(Unknown Source)
          at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
          at java.lang.reflect.Method.invoke(Method.java:597)
          at ognl.OgnlRuntime.invokeMethod(OgnlRuntime.java:851)
          at ognl.OgnlRuntime.callAppropriateMethod(OgnlRuntime.java:1253)
          at ognl.ObjectMethodAccessor.callMethod(ObjectMethodAccessor.java:68)
          at ognl.OgnlRuntime.callMethod(OgnlRuntime.java:1329)
          at ognl.ASTMethod.getValueBody(ASTMethod.java:90)
          at ognl.SimpleNode.evaluateGetValueBody(SimpleNode.java:212)
          at ognl.SimpleNode.getValue(SimpleNode.java:258)
          at ognl.ASTChain.getValueBody(ASTChain.java:141)
          at ognl.SimpleNode.evaluateGetValueBody(SimpleNode.java:212)
          at ognl.SimpleNode.getValue(SimpleNode.java:258)
          at ognl.Ognl.getValue(Ognl.java:494)
          at org.springframework.binding.expression.ognl.OgnlExpression.getValue(OgnlExpression.java:85)
          at org.springframework.webflow.action.EvaluateAction.doExecute(EvaluateAction.java:75)
          at org.springframework.webflow.action.AbstractAction.execute(AbstractAction.java:188)
          at org.springframework.webflow.execution.AnnotatedAction.execute(AnnotatedAction.java:145)
          at org.springframework.webflow.execution.ActionExecutor.execute(ActionExecutor.java:51)
          at org.springframework.webflow.engine.ActionState.doEnter(ActionState.java:101)
          at org.springframework.webflow.engine.State.enter(State.java:194)
          at org.springframework.webflow.engine.Transition.execute(Transition.java:227)
          at org.springframework.webflow.engine.impl.FlowExecutionImpl.execute(FlowExecutionImpl.java:391)
          at org.springframework.webflow.engine.impl.RequestControlContextImpl.execute(RequestControlContextImpl.java:214)
          at org.springframework.webflow.engine.TransitionableState.handleEvent(TransitionableState.java:119)
          at org.springframework.webflow.engine.Flow.handleEvent(Flow.java:555)
   at org.springframework.webflow.engine.impl.FlowExecutionImpl.handleEvent(FlowExecutionImpl.java:386)
          at org.springframework.webflow.engine.impl.RequestControlContextImpl.handleEvent(RequestControlContextImpl.java:210)
          at org.springframework.webflow.engine.ViewState.handleEvent(ViewState.java:254)
          at org.springframework.webflow.engine.ViewState.resume(ViewState.java:218)
          at org.springframework.webflow.engine.Flow.resume(Flow.java:545)
          at org.springframework.webflow.engine.impl.FlowExecutionImpl.resume(FlowExecutionImpl.java:259)
          at org.springframework.webflow.executor.FlowExecutorImpl.resumeExecution(FlowExecutorImpl.java:169)
          at org.springframework.webflow.mvc.servlet.FlowHandlerAdapter.handle(FlowHandlerAdapter.java:183)
          at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:790)
          at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:719)
          at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:644)
          at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:560)
          at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
          at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
          at org.jasig.cas.web.init.SafeDispatcherServlet.service_aroundBody2(SafeDispatcherServlet.java:115)
          at org.jasig.cas.web.init.SafeDispatcherServlet.service_aroundBody3$advice(SafeDispatcherServlet.java:44)
          at org.jasig.cas.web.init.SafeDispatcherServlet.service(SafeDispatcherServlet.java:1)
          at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
          at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
          at com.github.inspektr.common.web.ClientInfoThreadLocalFilter.doFilter(ClientInfoThreadLocalFilter.java:46)
          at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
          at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
          at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
          at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
          at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:237)
          at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:167)
          at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
          at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
          at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
          at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
          at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
          at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
          at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
          at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
          at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:852)
          at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
          at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
          at java.lang.Thread.run(Thread.java:662)
  </code></pre>