Solved

Why am I getting intermittent MySQLNonTransientConnectionException

Posted on 2010-08-28
3
677 Views
Last Modified: 2013-11-11
I have a spring/hibernate/mysql apoplication. If the server is sitting idle for a long time (> 8 hours), and I try to login, I get an MySQLNonTransientConnectionException. If I try to login again, I am able to successfully login. Looks like the DB connection is timing out, and then fail to reinitialize in time... Any help will be appreciated. Here is the full stack trace:


HTTP Status 500 -

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

org.springframework.transaction.CannotCreateTransactionException: Could not open Hibernate Session for transaction; nested exception is org.hibernate.TransactionException: JDBC begin failed:
      org.springframework.orm.hibernate3.HibernateTransactionManager.doBegin(HibernateTransactionManager.java:596)
      org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(AbstractPlatformTransactionManager.java:371)
      org.springframework.transaction.interceptor.TransactionAspectSupport.createTransactionIfNecessary(TransactionAspectSupport.java:336)
      org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:102)
      org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
      org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
      $Proxy141.loadUserByUsername(Unknown Source)
      org.springframework.security.authentication.dao.DaoAuthenticationProvider.retrieveUser(DaoAuthenticationProvider.java:82)
      org.springframework.security.authentication.dao.AbstractUserDetailsAuthenticationProvider.authenticate(AbstractUserDetailsAuthenticationProvider.java:124)
      org.springframework.security.authentication.ProviderManager.doAuthentication(ProviderManager.java:120)
      org.springframework.security.authentication.AbstractAuthenticationManager.authenticate(AbstractAuthenticationManager.java:48)
      org.springframework.security.authentication.ProviderManager.doAuthentication(ProviderManager.java:138)
      org.springframework.security.authentication.AbstractAuthenticationManager.authenticate(AbstractAuthenticationManager.java:48)
      org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter.attemptAuthentication(UsernamePasswordAuthenticationFilter.java:97)
      org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:200)
      org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:355)
      org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:105)
      org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:355)
      org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:79)
      org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:355)
      org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:149)
      org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:237)
      org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:167)
root cause

org.hibernate.TransactionException: JDBC begin failed:
      org.hibernate.transaction.JDBCTransaction.begin(JDBCTransaction.java:68)
      org.hibernate.impl.SessionImpl.beginTransaction(SessionImpl.java:1326)
      org.springframework.orm.hibernate3.HibernateTransactionManager.doBegin(HibernateTransactionManager.java:555)
      org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(AbstractPlatformTransactionManager.java:371)
      org.springframework.transaction.interceptor.TransactionAspectSupport.createTransactionIfNecessary(TransactionAspectSupport.java:336)
      org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:102)
      org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
      org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
      $Proxy141.loadUserByUsername(Unknown Source)
      org.springframework.security.authentication.dao.DaoAuthenticationProvider.retrieveUser(DaoAuthenticationProvider.java:82)
      org.springframework.security.authentication.dao.AbstractUserDetailsAuthenticationProvider.authenticate(AbstractUserDetailsAuthenticationProvider.java:124)
      org.springframework.security.authentication.ProviderManager.doAuthentication(ProviderManager.java:120)
      org.springframework.security.authentication.AbstractAuthenticationManager.authenticate(AbstractAuthenticationManager.java:48)
      org.springframework.security.authentication.ProviderManager.doAuthentication(ProviderManager.java:138)
      org.springframework.security.authentication.AbstractAuthenticationManager.authenticate(AbstractAuthenticationManager.java:48)
      org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter.attemptAuthentication(UsernamePasswordAuthenticationFilter.java:97)
      org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:200)
      org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:355)
      org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:105)
      org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:355)
      org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:79)
      org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:355)
      org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:149)
      org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:237)
      org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:167)
root cause

com.mysql.jdbc.exceptions.MySQLNonTransientConnectionException: Connection.close() has already been called. Invalid operation in this state.
      com.mysql.jdbc.SQLError.createSQLException(SQLError.java:888)
      com.mysql.jdbc.Connection.getMutex(Connection.java:3714)
      com.mysql.jdbc.Connection.setAutoCommit(Connection.java:5341)
      org.apache.commons.dbcp.DelegatingConnection.setAutoCommit(DelegatingConnection.java:331)
      org.apache.commons.dbcp.PoolingDataSource$PoolGuardConnectionWrapper.setAutoCommit(PoolingDataSource.java:317)
      org.hibernate.transaction.JDBCTransaction.begin(JDBCTransaction.java:63)
      org.hibernate.impl.SessionImpl.beginTransaction(SessionImpl.java:1326)
      org.springframework.orm.hibernate3.HibernateTransactionManager.doBegin(HibernateTransactionManager.java:555)
      org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(AbstractPlatformTransactionManager.java:371)
      org.springframework.transaction.interceptor.TransactionAspectSupport.createTransactionIfNecessary(TransactionAspectSupport.java:336)
      org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:102)
      org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
      org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
      $Proxy141.loadUserByUsername(Unknown Source)
      org.springframework.security.authentication.dao.DaoAuthenticationProvider.retrieveUser(DaoAuthenticationProvider.java:82)
      org.springframework.security.authentication.dao.AbstractUserDetailsAuthenticationProvider.authenticate(AbstractUserDetailsAuthenticationProvider.java:124)
      org.springframework.security.authentication.ProviderManager.doAuthentication(ProviderManager.java:120)
      org.springframework.security.authentication.AbstractAuthenticationManager.authenticate(AbstractAuthenticationManager.java:48)
      org.springframework.security.authentication.ProviderManager.doAuthentication(ProviderManager.java:138)
      org.springframework.security.authentication.AbstractAuthenticationManager.authenticate(AbstractAuthenticationManager.java:48)
      org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter.attemptAuthentication(UsernamePasswordAuthenticationFilter.java:97)
      org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:200)
      org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:355)
      org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:105)
      org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:355)
      org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:79)
      org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:355)
      org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:149)
      org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:237)
      org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:167)
note The full stack trace of the root cause is available in the Apache Tomcat/6.0.26 logs.
0
Comment
Question by:swsbuyer
  • 2
3 Comments
 
LVL 13

Expert Comment

by:Murali Murugesan
ID: 33608822
did u try increasing your connection pool idle time?
0
 
LVL 3

Expert Comment

by:durgaprasadn
ID: 34177086
At the first place are you using any connection pool or you are using the direct jdbc connections. If you are not using the connection pool for some reason Pls use the c3p0 or Apache dbcp connection pool which goes well with hibernate.
0
 
LVL 3

Accepted Solution

by:
durgaprasadn earned 500 total points
ID: 34177100
Connection pool would take care of reestablishing the connection if the connection dies for some reason.

MySQL terminates a connection after 8 hour timeout. You can modify the timeout by setting wait_timeout variable in MySQL.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question