These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 11 posts ] 
Author Message
 Post subject: "Connection reset" error after period of inactivit
PostPosted: Mon May 01, 2006 8:30 pm 
Newbie

Joined: Sun Feb 12, 2006 8:16 pm
Posts: 6
Hi! I'm getting this error every time I try to refresh a page or load a new one after about 5 minute period of inactivity.

Curiously, if I press refresh second time straight away after the error - the code works just fine. The problem is persistent.

It must be some sort of configuration problem, but I don't have any idea where to look. Can anyone suggest what I might try to do?

Hibernate version:
3.1

Name and version of the database you are using:
Microsoft SQL 2000

Full stack trace of any exception that occurs:
Hibernate: select settings0_.id from settings settings0_ where settings0_.id=?
[2/05/06 09:59:55:044 EST] 387288ec JDBCException W org.hibernate.util.JDBCExceptionReporter SQL Error: 0, SQLState: 08S01
[2/05/06 09:59:55:044 EST] 387288ec JDBCException E org.hibernate.util.JDBCExceptionReporter I/O Error: Connection reset
[2/05/06 09:59:55:044 EST] 387288ec DefaultLoadEv I org.hibernate.event.def.DefaultLoadEventListener Error performing load command
[2/05/06 09:59:55:044 EST] 387288ec DefaultLoadEv I org.hibernate.event.def.DefaultLoadEventListener TRAS0014I: The following exception was logged org.hibernate.exception.JDBCConnectionException: could not load an entity: [Settings#1]
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:72)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.loader.Loader.loadEntity(Loader.java:1799)
at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:93)
at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:81)
at org.hibernate.persister.entity.AbstractEntityPersister.load(AbstractEntityPersister.java:2730)
at org.hibernate.event.def.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:365)
at org.hibernate.event.def.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:346)
at org.hibernate.event.def.DefaultLoadEventListener.load(DefaultLoadEventListener.java:123)
at org.hibernate.event.def.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:161)
at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:87)
at org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:869)
at org.hibernate.impl.SessionImpl.load(SessionImpl.java:788)
at org.hibernate.impl.SessionImpl.load(SessionImpl.java:781)
at sun.reflect.GeneratedMethodAccessor95.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java(Compiled Code))
at java.lang.reflect.Method.invoke(Method.java(Compiled Code))
at org.hibernate.context.ThreadLocalSessionContext$TransactionProtectionWrapper.invoke(ThreadLocalSessionContext.java:292)
at $Proxy0.load(Unknown Source)
at HibernateUtil.loadSettings(HibernateUtil.java:320)
at getSettings(Init.java:123)
at execute(HomeAfterPrepare.java:48)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:419)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:224)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:414)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at com.ibm.ws.webcontainer.servlet.StrictServletInstance.doService(StrictServletInstance.java:110)
at com.ibm.ws.webcontainer.servlet.StrictLifecycleServlet._service(StrictLifecycleServlet.java:174)
at com.ibm.ws.webcontainer.servlet.IdleServletState.service(StrictLifecycleServlet.java:313)
at com.ibm.ws.webcontainer.servlet.StrictLifecycleServlet.service(StrictLifecycleServlet.java:116)
at com.ibm.ws.webcontainer.servlet.ServletInstance.service(ServletInstance.java:283)
at com.ibm.ws.webcontainer.servlet.ValidServletReferenceState.dispatch(ValidServletReferenceState.java:42)
at com.ibm.ws.webcontainer.servlet.ServletInstanceReference.dispatch(ServletInstanceReference.java:40)
at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:76)
at HibernateThreadFilter.doFilter(HibernateThreadFilter.java:64)
at com.ibm.ws.webcontainer.filter.FilterInstanceWrapper.doFilter(FilterInstanceWrapper.java:132)
at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:71)
at com.wedgetail.idm.sso.AuthFilter.doFilter(AuthFilter.java:128)
at com.wedgetail.idm.sso.forms.FormsAuthFilter.filter(FormsAuthFilter.java:342)
at com.wedgetail.idm.sso.forms.FormsAuthFilter.doFilter(FormsAuthFilter.java:299)
at com.ibm.ws.webcontainer.filter.FilterInstanceWrapper.doFilter(FilterInstanceWrapper.java:132)
at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:71)
at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.handleWebAppDispatch(WebAppRequestDispatcher.java:974)
at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.dispatch(WebAppRequestDispatcher.java:564)
at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.forward(WebAppRequestDispatcher.java:200)
at com.ibm.ws.webcontainer.srt.WebAppInvoker.doForward(WebAppInvoker.java:119)
at com.ibm.ws.webcontainer.srt.WebAppInvoker.handleInvocationHook(WebAppInvoker.java:276)
at com.ibm.ws.webcontainer.cache.invocation.CachedInvocation.handleInvocation(CachedInvocation.java:71)
at com.ibm.ws.webcontainer.cache.invocation.CacheableInvocationContext.invoke(CacheableInvocationContext.java:116)
at com.ibm.ws.webcontainer.srp.ServletRequestProcessor.dispatchByURI(ServletRequestProcessor.java:186)
at com.ibm.ws.webcontainer.oselistener.OSEListenerDispatcher.service(OSEListener.java:334)
at com.ibm.ws.webcontainer.http.HttpConnection.handleRequest(HttpConnection.java:56)
at com.ibm.ws.http.HttpConnection.readAndHandleRequest(HttpConnection.java:618)
at com.ibm.ws.http.HttpConnection.run(HttpConnection.java:439)
at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:672)
Caused by: java.sql.SQLException: I/O Error: Connection reset
at net.sourceforge.jtds.jdbc.TdsCore.executeSQL(TdsCore.java:1038)
at net.sourceforge.jtds.jdbc.JtdsStatement.executeSQLQuery(JtdsStatement.java:360)
at net.sourceforge.jtds.jdbc.JtdsPreparedStatement.executeQuery(JtdsPreparedStatement.java:672)
at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:139)
at org.hibernate.loader.Loader.getResultSet(Loader.java:1669)
at org.hibernate.loader.Loader.doQuery(Loader.java:662)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224)
at org.hibernate.loader.Loader.loadEntity(Loader.java:1785)
... 54 more
Caused by: java.net.SocketException: Connection reset
at java.net.SocketInputStream.read(SocketInputStream.java:194)
at java.io.DataInputStream.readFully(DataInputStream.java(Compiled Code))
at java.io.DataInputStream.readFully(DataInputStream.java:209)
at net.sourceforge.jtds.jdbc.SharedSocket.readPacket(SharedSocket.java:814)
at net.sourceforge.jtds.jdbc.SharedSocket.getNetPacket(SharedSocket.java(Inlined Compiled Code))
at net.sourceforge.jtds.jdbc.ResponseStream.getPacket(ResponseStream.java(Inlined Compiled Code))
at net.sourceforge.jtds.jdbc.ResponseStream.read(ResponseStream.java(Compiled Code))
at net.sourceforge.jtds.jdbc.ResponseStream.peek(ResponseStream.java:87)
at net.sourceforge.jtds.jdbc.TdsCore.wait(TdsCore.java:3772)
at net.sourceforge.jtds.jdbc.TdsCore.executeSQL(TdsCore.java:1031)
... 61 more


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 01, 2006 11:29 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
Looks like you're working with long-lived sessions. Do you have to? You should try to avoid that, if feasible. If you're working with a webapp, then there's pretty much no good reason to leave a session open for longer than it takes to handle the user's query.

If you genuinely need long-lived sessions, then you should consider putting in a watchdog or keepalive task that just calls "select 1" or somethng, every few seconds. JDBC connections do time out, it's done on purpose.

You may also be able to configure your server to not drop idle connections, but I don't know how to do that.

_________________
Code tags are your friend. Know them and use them.


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 02, 2006 12:54 am 
Newbie

Joined: Sun Feb 12, 2006 8:16 pm
Posts: 6
tenwit wrote:
Looks like you're working with long-lived sessions. Do you have to? You should try to avoid that, if feasible. If you're working with a webapp, then there's pretty much no good reason to leave a session open for longer than it takes to handle the user's query.


Thanks tenwit for the reply. Where should I look to fix this problem with long-lived session? I use servlet filter to manage hibernate sessions, it looks like this:

getSessionFactory()
beginTransaction()
chain.doFilter
getCurrentSession().getTransaction().commit()

Should I do something else?


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 02, 2006 1:32 am 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
You'll need a session.close()...

_________________
Code tags are your friend. Know them and use them.


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 02, 2006 2:24 am 
Newbie

Joined: Sun Feb 12, 2006 8:16 pm
Posts: 6
tenwit wrote:
You'll need a session.close()...


Changed it to:
getSessionFactory()
beginTransaction()
chain.doFilter
getCurrentSession().getTransaction().commit()
getCurrentSession().close()

Nothing changed. Still getting the same error. Any ideas?


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 02, 2006 5:45 am 
Pro
Pro

Joined: Mon Jan 24, 2005 5:39 am
Posts: 216
Location: Germany
Hi nausz,


tenwit wrote:
If you genuinely need long-lived sessions, then you should consider putting in a watchdog or keepalive task that just calls "select 1" or somethng, every few seconds. JDBC connections do time out, it's done on purpose.


Just follow this hint. You have to remind the database server from time
to time that you still need this connection.

_________________
dont forget to rate !


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 02, 2006 5:32 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
Actually steckemetz, I think nausz doesn't actually want long-lived sessions. The problem is that he's getting them unintentionally and they're timing out. Of course, hibernate does its own connection management, so when one connection times out and closes, hibernate detects this (next time) and opens a new one. Hence it working after hitting refresh twice.

So the solution involves finding out why the session's connection isn't closing after he's finish an application transaction (handling a user request, or whatever). Not having a session.close() was part of it, but obviously not enough. Afaik, the only time that session.close() doesn't close its connection is when the developer provides the JDBC connection to the session via sessionFactory.openSession(Connection). Is this what you do, nausz? If it is, you'll need code like this, when you're closing the session:
Code:
Connection con = session.close();
con.close();

_________________
Code tags are your friend. Know them and use them.


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 02, 2006 10:23 pm 
Newbie

Joined: Sun Feb 12, 2006 8:16 pm
Posts: 6
tenwit wrote:
Is this what you do, nausz? If it is, you'll need code like this, when you're closing the session


You're right, I don't need long-lived connection, but I don't do sessionFactory.openSession(Connection) either. I've just done search on the whole project to make 100% sure.
And if I add
Code:
Connection con = sf.getCurrentSession().close();
if (con != null) { con.close(); }

it doesn't help either.

I'd better post full code of my servlet filter here, maybe you can tell something from it.

Code:
private SessionFactory sf;
   
   public void doFilter(ServletRequest request,
                   ServletResponse response,
                   FilterChain chain)
         throws IOException, ServletException {

      try {
      
         sf = HibernateUtil.getSessionFactory();
         
         try {
            sf.getCurrentSession().beginTransaction();
            
         } catch (HibernateException e) {
            logger.warn(e.toString());
            logger.info("Starting transaction failed. Performing second attempt");
            // Try to initialize hibernate one more time
            sf.getCurrentSession().beginTransaction();
         }


         // Call the next filter (continue request processing)
         chain.doFilter(request, response);

logger.debug("Committing the database transaction");
         sf.getCurrentSession().getTransaction().commit();
         Connection con = sf.getCurrentSession().close();
         if (con != null)
            con.close();

      } catch (StaleObjectStateException staleEx) {
         logger.error("This interceptor does not implement optimistic concurrency control!");
         logger.error("Your application will not work until you add compensation actions!");
         // Rollback, close everything, possibly compensate for any permanent changes
         // during the conversation, and finally restart business conversation. Maybe
         // give the user of the application a chance to merge some of his work with
         // fresh data... what you do here depends on your applications design.
         throw staleEx;
      } catch (Throwable ex) {
         // Rollback only
         ex.printStackTrace();
         try {
            if (sf.getCurrentSession().getTransaction().isActive()) {
               sf.getCurrentSession().getTransaction().rollback();
            }
         } catch (Throwable rbEx) {
            logger.error("Could not rollback transaction after exception!", rbEx);
         }

         // Let others handle it... maybe another interceptor for exceptions?
         throw new ServletException(ex);
      }
   }

   public void init(FilterConfig filterConfig) throws ServletException {
   sf = HibernateUtil.getSessionFactory();

   }


Actually for some obscure reason I'm getting slightly different exception now:

DEBUG 03 May 2006 12:08:12
HibernateThreadFilter - Committing the database transaction [Servlet.Engine.Transports : 2]

[3/05/06 12:08:12:268 EST] 62d084fd JDBCTransacti E org.hibernate.transaction.JDBCTransaction JDBC commit failed

[3/05/06 12:08:12:300 EST] 62d084fd JDBCTransacti E org.hibernate.transaction.JDBCTransaction TRAS0014I: The following exception was logged java.sql.SQLException: I/O Error: Connection reset
at net.sourceforge.jtds.jdbc.TdsCore.executeSQL(TdsCore.java:1038)
at net.sourceforge.jtds.jdbc.TdsCore.submitSQL(TdsCore.java:884)
at net.sourceforge.jtds.jdbc.ConnectionJDBC2.commit(ConnectionJDBC2.java:1686)
at org.hibernate.transaction.JDBCTransaction.commitAndResetAutoCommit(JDBCTransaction.java:139)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:115)
at HibernateThreadFilter.doFilter(HibernateThreadFilter.java:71)
at com.ibm.ws.webcontainer.filter.FilterInstanceWrapper.doFilter(FilterInstanceWrapper.java:132)
at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:71)
at com.wedgetail.idm.sso.AuthFilter.doFilter(AuthFilter.java:128)
at com.wedgetail.idm.sso.forms.FormsAuthFilter.filter(FormsAuthFilter.java:342)
at com.wedgetail.idm.sso.forms.FormsAuthFilter.doFilter(FormsAuthFilter.java:299)
at com.ibm.ws.webcontainer.filter.FilterInstanceWrapper.doFilter(FilterInstanceWrapper.java:132)
at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:71)
at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.handleWebAppDispatch(WebAppRequestDispatcher.java:974)
at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.dispatch(WebAppRequestDispatcher.java:564)
at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.forward(WebAppRequestDispatcher.java:200)
at com.ibm.ws.webcontainer.srt.WebAppInvoker.doForward(WebAppInvoker.java:119)
at com.ibm.ws.webcontainer.srt.WebAppInvoker.handleInvocationHook(WebAppInvoker.java:276)
at com.ibm.ws.webcontainer.cache.invocation.CachedInvocation.handleInvocation(CachedInvocation.java:71)
at com.ibm.ws.webcontainer.srp.ServletRequestProcessor.dispatchByURI(ServletRequestProcessor.java:182)
at com.ibm.ws.webcontainer.oselistener.OSEListenerDispatcher.service(OSEListener.java:334)
at com.ibm.ws.webcontainer.http.HttpConnection.handleRequest(HttpConnection.java:56)
at com.ibm.ws.http.HttpConnection.readAndHandleRequest(HttpConnection.java:618)
at com.ibm.ws.http.HttpConnection.run(HttpConnection.java:439)
at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:672)
Caused by: java.net.SocketException: Connection reset
at java.net.SocketInputStream.read(SocketInputStream.java(Compiled Code))
at java.io.DataInputStream.readFully(DataInputStream.java(Compiled Code))
at java.io.DataInputStream.readFully(DataInputStream.java:209)
at net.sourceforge.jtds.jdbc.SharedSocket.readPacket(SharedSocket.java:814)
at net.sourceforge.jtds.jdbc.SharedSocket.getNetPacket(SharedSocket.java:695)
at net.sourceforge.jtds.jdbc.ResponseStream.getPacket(ResponseStream.java:443)
at net.sourceforge.jtds.jdbc.ResponseStream.read(ResponseStream.java:102)
at net.sourceforge.jtds.jdbc.ResponseStream.peek(ResponseStream.java:87)
at net.sourceforge.jtds.jdbc.TdsCore.wait(TdsCore.java:3772)
at net.sourceforge.jtds.jdbc.TdsCore.executeSQL(TdsCore.java:1031)
... 24 more


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 02, 2006 11:17 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
If your connection is reseting in the middle of a read, then you have some strange configuration in your DBMS. I can't help you there. However, is it possible that the action handling is taking a really long time? You begin the transactions before chain.doFilter(), and the problem manifests after chain.doFilter()... is there a big time difference? If there is, perhaps you should see about reducing that difference.

BTW, there's a bug in that filter. If sf.getCurrentSession().beginTransaction() throws an exception, you continue on to close the transaction. You shouldn't do that, you should close the session immediately, and get a new session.

_________________
Code tags are your friend. Know them and use them.


Top
 Profile  
 
 Post subject: Re: "Connection reset" error after period of inactivit
PostPosted: Tue Jul 12, 2011 4:46 pm 
Newbie

Joined: Tue Jul 12, 2011 4:36 pm
Posts: 2
I have the same problem, and it's been already 7 years since this was posted.

Does anyone knows the solution yet?


Top
 Profile  
 
 Post subject: Re: "Connection reset" error after period of inactivit
PostPosted: Wed Feb 01, 2012 5:45 am 
Newbie

Joined: Sun Oct 11, 2009 7:17 pm
Posts: 8
Still waiting :)

_________________
Kremsoft
Software Development Outsourcing http://www.kremsoft.com


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 11 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.