Announcement Announcement Module
Collapse
No announcement yet.
Connection reset by peer: socket write error Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Connection reset by peer: socket write error

    in my system, I use struts+spring+hibernate. I find spring declarative transaction can not reconnect the database when database works well after some disaster such as interruption of network or database server down.

    How to config the context file to avoid this!
    ------------------------------------------------------------------------------------------------
    applicationContext.xml :

    <!-- Hibernate SessionFactory -->
    <bean id="sessionFactory" class="org.springframework.orm.hibernate.LocalSess ionFactoryBean">
    <property name="configLocation"> <value>classpath:hibernate.cfg.xml</value></property>
    </bean>

    <!-- Transaction manager for a single Hibernate SessionFactory (alternative to JTA) -->
    <bean id="transactionManager" class="org.springframework.orm.hibernate.Hibernate TransactionManager">
    <property name="sessionFactory"><ref local="sessionFactory"/></property>
    </bean>
    ---------------------------------------------------------------------------------------------------------
    hibernate.cfg.xml:

    <property name="connection.driver_class">com.mysql.jdbc.Driv er</property>
    <property name="connection.url">jdbc:mysql://192.168.12.99:3306/test?useUnicode=true&characterEncoding=gb2312</property>

    <property name="connection.username">hello</property>
    <property name="connection.password"></property>
    <property name="connection.pool_size">5</property>
    <property name="dialect">net.sf.hibernate.dialect.MySQLDiale ct</property>
    <property name="hibernate.show_sql">true</property>

    <property name="transaction.factory_class">net.sf.hibernate. transaction.JDBCTransactionFactory</property>

    --------------------------------------------------------------------------------------------------------
    the error information is:


    2004-11-04 15:04:25,906 >> ERROR >> HttpProcessor[8083][3] >> net.sf.hibernate.JDBCException.<init>(JDBCExceptio n.java:38) >> Could not execute JDBC batch update
    java.sql.BatchUpdateException: Communication link failure: java.net.SocketException, underlying cause: Connection reset by peer: socket write error

    ** BEGIN NESTED EXCEPTION **

    java.net.SocketException
    MESSAGE: Connection reset by peer: socket write error

    STACKTRACE:

    java.net.SocketException: Connection reset by peer: socket write error
    at java.net.SocketOutputStream.socketWrite0(Native Method)
    at java.net.SocketOutputStream.socketWrite(SocketOutp utStream.java:92)
    at java.net.SocketOutputStream.write(SocketOutputStre am.java:136)
    at java.io.BufferedOutputStream.flushBuffer(BufferedO utputStream.java:69)
    at java.io.BufferedOutputStream.flush(BufferedOutputS tream.java:127)
    at com.mysql.jdbc.MysqlIO.send(MysqlIO.java:1764)
    at com.mysql.jdbc.MysqlIO.send(MysqlIO.java:1727)
    at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:11 48)
    at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java :1278)
    at com.mysql.jdbc.Connection.execSQL(Connection.java: 2247)
    at com.mysql.jdbc.PreparedStatement.executeUpdate(Pre paredStatement.java:1772)
    at com.mysql.jdbc.PreparedStatement.executeBatch(Prep aredStatement.java:1448)
    at net.sf.hibernate.impl.BatchingBatcher.doExecuteBat ch(BatchingBatcher.java:54)
    at net.sf.hibernate.impl.BatcherImpl.executeBatch(Bat cherImpl.java:126)
    at net.sf.hibernate.impl.SessionImpl.executeAll(Sessi onImpl.java:2421)
    at net.sf.hibernate.impl.SessionImpl.execute(SessionI mpl.java:2371)
    at net.sf.hibernate.impl.SessionImpl.flush(SessionImp l.java:2240)
    at net.sf.hibernate.transaction.JDBCTransaction.commi t(JDBCTransaction.java:61)
    at org.springframework.orm.hibernate.HibernateTransac tionManager.doCommit(HibernateTransactionManager.j ava:463)
    at org.springframework.transaction.support.AbstractPl atformTransactionManager.commit(AbstractPlatformTr ansactionManager.java:373)
    at org.springframework.transaction.interceptor.Transa ctionAspectSupport.doCommitTransactionAfterReturni ng(TransactionAspectSupport.java:242)
    at org.springframework.transaction.interceptor.Transa ctionInterceptor.invoke(TransactionInterceptor.jav a:66)
    at org.springframework.aop.framework.ReflectiveMethod Invocation.proceed(ReflectiveMethodInvocation.java :138)
    at org.springframework.aop.framework.JdkDynamicAopPro xy.invoke(JdkDynamicAopProxy.java:152)
    at $Proxy0.storeUser(Unknown Source)
    at example.framework.org.action.UserManagerAction.tes tDAO(UserManagerAction.java:68)
    at example.framework.org.action.UserManagerAction.exe cute(UserManagerAction.java:23)
    at org.apache.struts.action.RequestProcessor.processA ctionPerform(RequestProcessor.java:484)
    at org.apache.struts.action.RequestProcessor.process( RequestProcessor.java:274)
    at org.apache.struts.action.ActionServlet.process(Act ionServlet.java:1482)
    at org.apache.struts.action.ActionServlet.doPost(Acti onServlet.java:525)
    at javax.servlet.http.HttpServlet.service(HttpServlet .java:760)
    at javax.servlet.http.HttpServlet.service(HttpServlet .java:853)
    at org.apache.catalina.core.ApplicationFilterChain.in ternalDoFilter(ApplicationFilterChain.java:247)
    at org.apache.catalina.core.ApplicationFilterChain.do Filter(ApplicationFilterChain.java:193)
    at org.apache.catalina.core.StandardWrapperValve.invo ke(StandardWrapperValve.java:243)
    at org.apache.catalina.core.StandardPipeline.invokeNe xt(StandardPipeline.java:566)
    at org.apache.catalina.core.StandardPipeline.invoke(S tandardPipeline.java:472)
    at org.apache.catalina.core.ContainerBase.invoke(Cont ainerBase.java:943)
    at org.apache.catalina.core.StandardContextValve.invo ke(StandardContextValve.java:190)
    at org.apache.catalina.core.StandardPipeline.invokeNe xt(StandardPipeline.java:566)
    at org.apache.catalina.valves.CertificatesValve.invok e(CertificatesValve.java:246)
    at org.apache.catalina.core.StandardPipeline.invokeNe xt(StandardPipeline.java:564)
    at org.apache.catalina.core.StandardPipeline.invoke(S tandardPipeline.java:472)
    at org.apache.catalina.core.ContainerBase.invoke(Cont ainerBase.java:943)
    at org.apache.catalina.core.StandardContext.invoke(St andardContext.java:2347)
    at org.apache.catalina.core.StandardHostValve.invoke( StandardHostValve.java:180)
    at org.apache.catalina.core.StandardPipeline.invokeNe xt(StandardPipeline.java:566)
    at org.apache.catalina.valves.ErrorDispatcherValve.in voke(ErrorDispatcherValve.java:170)
    at org.apache.catalina.core.StandardPipeline.invokeNe xt(StandardPipeline.java:564)
    at org.apache.catalina.valves.ErrorReportValve.invoke (ErrorReportValve.java:170)
    at org.apache.catalina.core.StandardPipeline.invokeNe xt(StandardPipeline.java:564)
    at org.apache.catalina.core.StandardPipeline.invoke(S tandardPipeline.java:472)
    at org.apache.catalina.core.ContainerBase.invoke(Cont ainerBase.java:943)
    at org.apache.catalina.core.StandardEngineValve.invok e(StandardEngineValve.java:174)
    at org.apache.catalina.core.StandardPipeline.invokeNe xt(StandardPipeline.java:566)
    at org.apache.catalina.core.StandardPipeline.invoke(S tandardPipeline.java:472)
    at org.apache.catalina.core.ContainerBase.invoke(Cont ainerBase.java:943)
    at org.apache.catalina.connector.http.HttpProcessor.p rocess(HttpProcessor.java:1027)
    at org.apache.catalina.connector.http.HttpProcessor.r un(HttpProcessor.java:1125)
    at java.lang.Thread.run(Thread.java:536)


    ** END NESTED EXCEPTION **


    at com.mysql.jdbc.PreparedStatement.executeBatch(Prep aredStatement.java:1492)
    at net.sf.hibernate.impl.BatchingBatcher.doExecuteBat ch(BatchingBatcher.java:54)
    at net.sf.hibernate.impl.BatcherImpl.executeBatch(Bat cherImpl.java:126)
    at net.sf.hibernate.impl.SessionImpl.executeAll(Sessi onImpl.java:2421)
    at net.sf.hibernate.impl.SessionImpl.execute(SessionI mpl.java:2371)
    at net.sf.hibernate.impl.SessionImpl.flush(SessionImp l.java:2240)
    at net.sf.hibernate.transaction.JDBCTransaction.commi t(JDBCTransaction.java:61)
    at org.springframework.orm.hibernate.HibernateTransac tionManager.doCommit(HibernateTransactionManager.j ava:463)
    at org.springframework.transaction.support.AbstractPl atformTransactionManager.commit(AbstractPlatformTr ansactionManager.java:373)
    at org.springframework.transaction.interceptor.Transa ctionAspectSupport.doCommitTransactionAfterReturni ng(TransactionAspectSupport.java:242)
    at org.springframework.transaction.interceptor.Transa ctionInterceptor.invoke(TransactionInterceptor.jav a:66)
    at org.springframework.aop.framework.ReflectiveMethod Invocation.proceed(ReflectiveMethodInvocation.java :138)
    at org.springframework.aop.framework.JdkDynamicAopPro xy.invoke(JdkDynamicAopProxy.java:152)
    at $Proxy0.storeUser(Unknown Source)
    at example.framework.org.action.UserManagerAction.tes tDAO(UserManagerAction.java:68)
    at example.framework.org.action.UserManagerAction.exe cute(UserManagerAction.java:23)
    at org.apache.struts.action.RequestProcessor.processA ctionPerform(RequestProcessor.java:484)
    at org.apache.struts.action.RequestProcessor.process( RequestProcessor.java:274)
    at org.apache.struts.action.ActionServlet.process(Act ionServlet.java:1482)
    at org.apache.struts.action.ActionServlet.doPost(Acti onServlet.java:525)
    at javax.servlet.http.HttpServlet.service(HttpServlet .java:760)
    at javax.servlet.http.HttpServlet.service(HttpServlet .java:853)
    at org.apache.catalina.core.ApplicationFilterChain.in ternalDoFilter(ApplicationFilterChain.java:247)
    at org.apache.catalina.core.ApplicationFilterChain.do Filter(ApplicationFilterChain.java:193)
    at org.apache.catalina.core.StandardWrapperValve.invo ke(StandardWrapperValve.java:243)
    at org.apache.catalina.core.StandardPipeline.invokeNe xt(StandardPipeline.java:566)
    at org.apache.catalina.core.StandardPipeline.invoke(S tandardPipeline.java:472)
    at org.apache.catalina.core.ContainerBase.invoke(Cont ainerBase.java:943)
    at org.apache.catalina.core.StandardContextValve.invo ke(StandardContextValve.java:190)
    at org.apache.catalina.core.StandardPipeline.invokeNe xt(StandardPipeline.java:566)
    at org.apache.catalina.valves.CertificatesValve.invok e(CertificatesValve.java:246)
    at org.apache.catalina.core.StandardPipeline.invokeNe xt(StandardPipeline.java:564)
    at org.apache.catalina.core.StandardPipeline.invoke(S tandardPipeline.java:472)
    at org.apache.catalina.core.ContainerBase.invoke(Cont ainerBase.java:943)
    at org.apache.catalina.core.StandardContext.invoke(St andardContext.java:2347)
    at org.apache.catalina.core.StandardHostValve.invoke( StandardHostValve.java:180)
    at org.apache.catalina.core.StandardPipeline.invokeNe xt(StandardPipeline.java:566)
    at org.apache.catalina.valves.ErrorDispatcherValve.in voke(ErrorDispatcherValve.java:170)
    at org.apache.catalina.core.StandardPipeline.invokeNe xt(StandardPipeline.java:564)
    at org.apache.catalina.valves.ErrorReportValve.invoke (ErrorReportValve.java:170)
    at org.apache.catalina.core.StandardPipeline.invokeNe xt(StandardPipeline.java:564)
    at org.apache.catalina.core.StandardPipeline.invoke(S tandardPipeline.java:472)
    at org.apache.catalina.core.ContainerBase.invoke(Cont ainerBase.java:943)
    at org.apache.catalina.core.StandardEngineValve.invok e(StandardEngineValve.java:174)
    at org.apache.catalina.core.StandardPipeline.invokeNe xt(StandardPipeline.java:566)
    at org.apache.catalina.core.StandardPipeline.invoke(S tandardPipeline.java:472)
    at org.apache.catalina.core.ContainerBase.invoke(Cont ainerBase.java:943)
    at org.apache.catalina.connector.http.HttpProcessor.p rocess(HttpProcessor.java:1027)
    at org.apache.catalina.connector.http.HttpProcessor.r un(HttpProcessor.java:1125)
    at java.lang.Thread.run(Thread.java:536)

  • #2
    I guess the connection pool still holds old connections, which are invalid.
    If possible I would propose to configure the pool to check the contained connections for validity and discard invalid ones.
    In my opinion it is rather an issue of the hibernate part of the configuration. But since I have no detailed knowledge about hibernate configuration, I cannot help you any further.

    Regards,
    Andreas

    Comment


    • #3
      This should normally be configured at the JDBC driver and/or connection pool level. It's not really an application concern, as the application is not actually managing the real connections. Most DataSource impementations have some sort of control over the strategy to use to check to see if the connection is still valid, reconnection, etc.

      Comment

      Working...
      X